Posts

Extract values from vary controls and Write it on XML

This has found in forum who shared the problem and solution as mentioned above title. Background: A form contains many controls, such as TextBox, ComboBox and etc... Then, we need to extract the value from these options. The code example is as below: foreach ( Control control in this . Controls ) {     //here 'this' is representing the form you want to iterate through     //you can check whether it is a combobox or a text box     if ( control . GetType () == typeof ( Combobox ))     {         //this is a combo box     }     else if ( control . GetType () == typeof ( Textbox ))     {         //this is a text box     } } This is a nice example as for beginner like me ^^/ Link: http://stackoverflow.com/questions/6400382/how-do-i-extract-values-from-controls-and-write-it-on-xml

Save and Read Combo Box Items from an XML File

Image
Introduction When discussing file processing, we mentioned that it is sometimes necessary to automatically save a file when an application exits, without any intervention from the user. You can also solve this exact problem using XML. The ever growing strength of XML is in its ability to let modify a file however but still make that file usable by any environment that needs its content. We are going to create an XML file that holds a list of items for a combo box. Once the file exists, it can be processed or modified by any application that can read XML. We will load the file automatically when the application opens and retrieve the values of the elements to complete a combo box . While using the application, we will allow the user to change the list. When the application closes, we will retrieve the list of items from the combo box and update (in reality) recreate the list that includes the new items. Practical Learning: Using XML Values 1. Related link:Start Visual C# and cr

How to read APP.CONFIG for user defined run-time parameters

These are the steps involved in defining runtime parameters and using them in your code. 1. Create a App.Config file 2. Define the runtime parameters and provide values for these 3. Access these parameters in your code 4. Verify changing the parameter value at runtime affects the application Step 1: Create App.Config file 1a. Create a Console Application 1b. In Solution Explorer, right click on project. Add->New Item. Select Application Configuration file. This file will be added to your project. Step 2: Define the runtime parameters and provide values for these 2a. Open App.Config. 2b. Define the keys and values for your runtime parameters. Example: You can define any key and provide values. Ensure you don’t have duplicate keys. Step 3: Access these parameters in your code 3a. Add a refernce System.Configuration DLL. 1 3b. Add the following lines in your code. You can directly add these lines in Main. Example: string name = System.Configuration.Conf

Visual C# Controls Tutorial - ComboBoxes

Image

Creating Multiple Forms in C#.NET

Image
There aren't many programmes that have only one form. Most programmes have other forms that are accessible from the main one that loads at start up. In this section, you'll learn how to create programmes with more than one form in C#.NET . The programme we'll create is very simple one. It will have a main form with a text box and a button. When the button is clicked, it will launch a second form. On the second form, we'll allow a user to change the case of the text in the text box on form one. Here's what form one looks like: Design the above form. Set the Name property of the text box to txtChangeCase . For the Text property, add some default text, but all in lowercase letters. Set the Name property of the button to btnFormTwo . Adding a new form to the project is easy. Click Project from the menu bar at the top of the Visual C# software. From the Project menu, select Add New Windows Form . You'll see the Add New Item dialogue box appear. Make

Split Container Control in C#

Image
What is Split Container control in C# ? Split Container control provides functionality of a splitter to divide and resize two controls.You can place it at form horizontally or vertically by specifiying Orientation property each represents left/top and right/bottom panels respectively. Useful properties: AutoScroll:  This property when set to true, allows scroll bars to be displayed. BackColor:  The background color of the SplitContainer is defaulted to System.Drawing.SystemColors.Control, but this can be set to any color you like. The whole of the SplitContainer changes color, however, each Panel can have its own background color. BackgroundImage : Instead of a single color, an image can be displayed as the background. The image only appears in the splitter bar. BorderStyle:  This property determines if the panel is outlined with no visible border (None), a plain line (FixedSingle), or a shadowed line (Fixed3D). Dock:  Determines which SplitContainer borders are attac

Calling Win32 DLLs in C# with P/Invoke

Image
Unmanaged Code BOOL MessageBeep(   UINT uType   // beep type ); Managed Code [DllImport ("User32.dll")] static extern Boolean MessageBeep (UInt32 beepType); Note: Static 1.The MessageBeep method was declared as static.  2.This is a requirement for P/Invoke methods because there is no consistent notion of an instance in the  Window API. Extern 1. It is not a method call, but an extern method definition. 2. This is your hint to the compiler that you mean for the method to be implemented by a function exported from a DLL, and therefore there is no need for you to supply a method body. 3. P/Invoke methods are nothing more than metadata that the just-in-time (JIT) compiler uses to wire managed code to an unmanaged DLL function at run time.  4. An important piece of information required to perform this wiring to the unmanaged world is the name of the DLL from which the unmanaged method is exported .  6. The DllImport custom attribu