Custom Search

Saturday, January 31, 2009

EXAMPLE 5

EXAMPLE # 5

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b, c,d,e;
double f,g;
string str,ptr;
Console.WriteLine("ENTER A 1 SUBJECT NUMBER");
a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nENTER A 2 SUBJECT NUMBER");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nENTER A TOTAL NUMBER OF SUBJECTS");
e=Convert.ToInt32 (Console.ReadLine());
c = a + b;
Console.WriteLine("\nADD SUBJECTS NUMBER");
str = Convert.ToString(c);
Console.WriteLine(str);
d = c * 100;
Console.WriteLine("\nMULTIPLY BY 100");
ptr = Convert.ToString(d);
Console.WriteLine(ptr);
f =Convert.ToDouble(d / e);
Console.WriteLine("\nTOTAL PERCENTAGE");
Console.WriteLine(f);
}
}
}

Friday, January 30, 2009

EXAMPLE 4

EXAMPLE # 4:-


using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i <= 10; i++)
{
Console.WriteLine("YOU ARE A BOY");
}
}
}
}

EXAMPLE 3

EXAMPLE # 3:-


using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b, c;
string d;
Console.WriteLine("ENTER A FIRST NUMBER:");
a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ENTER A SECOND NUMBER:");
b=Convert.ToInt32(Console.ReadLine());
c = a + b;
d = Convert.ToString(c);
Console.WriteLine("RESULT");
Console.WriteLine(d);
}
}
}

EXAMPLE 2

EXAMPLE # 2:-

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ENTER A NAME");
Console.ReadLine();
}
}
}

EXAMPLE 1

EXAMPLE # 1:-

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\n\nHELLO");
}
}
}

C# SINGLE DIMENSION ARRAY CREATION

INTRODUCTION:-
An array is a technique of storing information of different items in a common variable of one name.
CODING EXAMPLE:-
This type of list can be created using a string-based array. Here is an example:
private void Form1_Load(object sender, System.EventArgs e)
{
string[] lstItemsNames = { "Women Coat", "Men Jacket", "Teen Jeans",
"Children Playground Dress" };
}
The above type of list is referred to as a single-dimensional. To provide more information about items, you can associate a second or even a third list to the first as follows:private void Form1_Load(object sender, System.EventArgs e)
{
string[] itemsNumbers = { "624376", "274952", "749752", "394085" };
string[] lstItemsNames = { "Women Coat", "Men Jacket", "Teen Jeans",
"Children Playground Dress" };
double[] itemsPrices = { 225.55, 175.75, 24.50, 75.05 };
}

C# CONTROL DATE TIME PICKER




INTRODUCTION:-

The Date and Time Picker is a control that allows the user to select either a date or a time value. This control provides two objects in one:

One of the advantages of the Date and Time Picker control is that it allows the user to select a time or a date value instead of typing it. This tremendously reduces the likelihood of mistakes.
To create a Date or Time Picker control, add a DateTimePicker control to a form or other container. The DateTimePicker control is based on the DateTimePicker class. In reality, the DateTimePicker control can be considered as two controls in one: you just have to choose which one of both controls you want to use.
TIME PICKER:-
The Time Picker control is a spin button made of different sections: the hours value, the minutes value, the optional seconds value, and the optional AM/PM string. To change the time, the user clicks a section and uses either the mouse or the keyboard to increase or decrease that particular value. To change another value, the user must first click it and then use the spin button.
By default, the time displays using the H:M:SS AM/PM format. This means that the time uses 1 digit for the hours from 0 to 9, 1 digit for the minutes from 0 to 9, 1 digit for the seconds from 0 to 9 and the AM or PM for morning or afternoon. To customize the way the time displays, first set the Format property to Custom. Then, in the CustomFormat property, use a combination of the following characters to create a custom format:

Format Used For Description
h Hour for 12-hour basis Used to display the hour with one digit if
the value is less than 10

hh Hour for 12-hour basis Used to display the hour with a leading 0 if
the value is less than 10

H Hour for 24-hour basis Used to display the hour with one digit if the
value is less than 10

HH Hour for 24-hour basis Used to display the hour with a leading 0 if
the value is less than 10

m Minute Used to display the minute with one digit if
the value is less than 10

mm Minute Used to display the minute with a leading 0 if
the value is less than 10

t AM/PM Displays the letter A or P for the AM or PM
section

tt AM/PM Displays the letters AM or PM for the last
section


You can set the format at design time using the Format field on the Properties window. To set the format at run time, assign the desired format to the DateTimePicker.CustomFormat property.
By default, after adding the control to the form or container, it assumes the time of the computer when the control was added. If you want to set a different time, apply a Format combination to the Value property. In the same way, at any time, you can retrieve the time value on the control by accessing the Value property.







C# CONTROL RADIO BUTTONS

INTRODUCTION:-
A radio button, sometimes called an option button, is circular control that comes in a group with other controls of the same type. Each radio button is made of a small empty circle O. From the group, when the user clicks one of them, the radio button that was clicked becomes filled with a big dot 8. When one of the radio buttons in the group is selected and displays its dot, the others display empty circles. To guide the user as to what the radio buttons mean, each is accompanied by a label.
To create a radio button, on the Toolbox, you can click the RadioButton control . Alternatively, you can declare a RadioButton class and use the form's constructor to initialize the radio buttons. Because radio buttons always come as a group, you should include them in another control that visibly shows that the radio buttons belong to the same group. The most common control used for this purpose is the group box created using the GroupBox control
CODE OF RADIO BUTTON:-
If (radiobutton1.Checked==true)
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Error");
}

Thursday, January 29, 2009

C# CONTROL LINK LABELS

INTRODUCTION:-

In the pass, to add an internet or email link to a form, there were many steps to follow. As the internet and email had become an integral part of the culture, it was also time to have an appropriate control adapted for this need. To address this issue, a control called LinkLabel was added to the .NET Framework.

WORKING OF A LINK LABEL:-

Link label to provide link to another pages to click the link lable color is change to supose that you have click the link label and color donot change so you have choose the before click color and after click color is same select.

C# CONTROL CHECKBOX

INTRODUCTION:-
A check box is a control that makes a statement true or false. To perform this validation, this control displays a small square box that the user can click. To start, the square box may be empty . If the user clicks it, a check mark appears in the square box . If the user clicks a check box that has a check mark in it, the check mark may be removed. When the square box is empty *, the statement is false. When the square box is filled with a check mark T, the statement is true.
To let the user know what the check box control represents, the control is accompanied by a label that displays the statement.
To create a check box control, you can use the CheckBox class that is implemented by the CheckBox control of the Toolbox.
TO ACTIVATE THE CHECK BOX CODING:-
if(checkbox1.Checked==true)
{
Messagebox.Show("CHECKBOX1 ACTIVAT");
}
else
{
Messagebox.Show("CheckBox2 Activate");
}

C# CONTROL TEXTBOX

INTRODUCTION:-
A text box is a Windows control used to get or display text for the user’s interaction. At its most regular use, a text box serves as a place to fill out and provide information. Such a use is common on employment applications, login dialog boxes, etc. Like most other controls, the role of a text box is not obvious at first glance; that is why it should be accompanied by a label that defines its purpose.
From the user’s standpoint, a text box is named after the label closest to it. Such a label is usually positioned to the left or the top side of the text box. From the programmer’s point of view, a text box is a placeholder used for various things. For example, you can show or hide it as you see fit. You can also use it only to display text without allowing the user to change it.
To create a text box, in the Toolbox, you can click TextBox and click the form. The text box is based on the TextBox class. This means that you can use this class to dynamically create a text box and add it to your application.


TEXT BOX CHARACTERISTICS:-

The most important aspect of a text box is its text, whether it is displaying or requesting it. This is the Text property. When you add a text box control to a form or other container, the Form Designer initializes it with the name of the control; this would be textBox1 for the first text box, textBox2 for the second, etc. If you want the control to display some text when the form launches, type the text in the Text property field in the Properties window. Otherwise, if you want the text box to be empty when it comes up for the first time, delete the content of the Text field.
By default, a newly created text box is used to both display and receive text from the user. If you want the user to read text without being able to change it, set the ReadOnly Boolean property to True. Its default value is false.
As mentioned already, a text box should be accompanied by a label that indicates what it is used for. To support this relationship, the Label control provides various properties. An accelerator character is a symbol of the label that provides easy access to its text box. On the label, such a character is underlined. An example would be First Name. The idea is that, if the user presses the Alt key in combination with the label’s underlined character, the text box it accompanies would receive focus. To create an accelerator key, choose one of the label’s characters and precede it with an ampersand character when setting its caption. An example would be &First Name. If you want a label to display the accelerator character instead of a plain ampersand, set the label’s UseMnemonic property to true, which is already its default value. If you set it to true but need to display an ampersand, type two & characters where the ampersand would be shown.
The UseMnemonic property of a label is only used to indicate that the label would display an accelerator character and the & symbol typed on the label creates that accelerator character. To indicate which text box would receive focus when the accelerator character of the label is invoked, you must make sure you establish an appropriate tab sequence using the Tab Order menu item from the main menu or using the combination of TabStop/TabIndex properties. Typically, the label should have a Tab Order or TabIndex value that is just - 1 of that of the control it serves.
A text box can be configured to display only lowercase characters, only uppercase characters, or a mix. This characteristic is controlled by the CharacterCasing property, which is an enumerator that holds the same name. The default value of this property is Normal, which indicates that the control can use a mix of lowercase and uppercase characters. If you set this property to Lower, all existing characters, if any, in the control would be converted to lowercase and all future characters typed in the control would be automatically converted to lowercase. If you set this property to Upper, all existing characters, if any, in the control would be converted to uppercase and all future characters typed in the control would be automatically converted to uppercase.
Text typed in a text box appears with its corresponding characters unless you changed the effect of the CharacterCasing property from its default Normal value. This allows the user to see and be able to read the characters of the control. If you prefer to make them un-readable, you can use the PasswordChar property. Although this property is a char type of data, changing it actually accomplishes two things. If you type a character in its field in the Properties window, for example if you type *, any character typed in it would be un-readable and be replaced by the value of this property. You can use any alphabetic character or digit to represent the characters that would be typed but you must provide only one character.


CODING OF TEXT BOX:-

Print in text box:

Textbox1.Text="WINDOW FORM";

JOINING:

Textbox1.Text+="WINDOW FORM";

C# CONTROL PROGRESS BAR


INTRODUCTION:-
A progress bar is a control that displays (small) rectangles that are each filled with a color. These (small) rectangles are separate but adjacent each other so that, as they display, they produce a bar. To have the effect of a progress bar, not all these rectangles display at the same time. Instead, a numeric value specifies how many of these (small) rectangles can display at one time.
To create a progress bar, use the ProgressBar control from the Toolbox. The ProgressBar control is based on the ProgressBar class.
Characteristics of a Progress Bar
After adding it to an application, a progress bar assumes a horizontal position (the actual progress bar of Microsoft Windows, as implemented in Win32, can also have a vertical orientation; the .NET Framework's version has this and other limitations).
To show its effect, the progress bar draws its small rectangles as a bar. These small rectangles are from a starting position to an end. This means that the progress bar uses a range of values. This range is controlled by the Minimum and the Maximum properties whose default values are 0 and 100 respectively. At design time, you can set them using the limits of an integer. The small rectangles are drawn from the left (the Minimum value) to the right (the Maximum value) sides of the control.
At one particular time, the most right rectangle of a progress bar is referred to as its position and it is represented by the Value property. At design time, to set a specific position for the control, change the value of the Value property whose default is 0. The position must always be between the Minimum and Maximum values. At design time, if you change the Minimum to a value higher than the Value property, the value of Value would be increased to the new value of Minimum. If you set the value of Value to a value lower than the Minimum, You would receive an error:


After clicking OK, the value of the Minimum would be reset to that of the Value property. In the same way, if you set the value of Value to a value higher than Maximum, you would receive an error. At run time, you can assign the desired value to the Value property. Once again, avoid specifying a value that is out of range.
Because a progress bar is usually meant to indicate the progress of an activity, when drawing its small rectangles, it increases its current position in order to draw the next rectangle, except if the control is reset. The number of units that the control must increase its value is controlled by the Step property. By default, it is set to 10. Otherwise, you can set it to a different value of your choice.
When the control draws one of its rectangles based on the Step value, it calls the PerformStep(). Its syntax is: public void PerformStep();
After a small rectangle has been drawn, the current value is incremented by the value of the Step property. If you want to increment the value of the control to a value other than that of the the Step property, then call the Increment() method. Its syntax is: public void Increment(int value);
The amount by which to increment is passed to the method.

C# CONTROL MULTILINE TEXTBOX

INTRODUCTION:-
The TextBox control is equipped with one particular property that, when considered, changes the control tremendously. This property is called Multiline. Multiline is a Boolean property whose default value is false. If it is set to a true value, it allows the control to display multiple lines of text, unlike the normal text box that can display only one line.

CHARACTERISTICS OF A MULTILINE TEXTBOX:-
To create a multi-line, after adding a TextBox control to a form, probably the first action you should take is to set its Multiline Boolean property to True. After the TextBox control has been added to the form, it is positioned where you drop it at design time. If you are creating a text editor, you can use the Dock property to specify how much room of the form the text box would use.
The user mostly reads and/or enters text in the multi-line text box when interacting with the control. At design time, you can set the text that would display when the multi-line text box comes up. To enter this text, in the Properties window, click the Lines field to reveal its ellipsis button that allows you to open the String Collection Editor. If you want the control to be empty at startup, delete the content of the String Collector Editor and click OK. Otherwise, type the desired text and click OK.
The user, on the other hand has the ability to type text to alter the content of the multi-line text box. This is possible only if the ReadOnly property is set to True, which is the default. If you want to prevent the user from altering the text in the multi-line text box, set the ReadOnly property to False. You can also do this programmatically.
When a multi-line text box opens, the compiler registers the content of the control. If the user has the ability to change the text in the control and if the user changes it, the compiler flags the control as Modified. This allows you to take actions. You can acknowledge this by programmatically setting the Modified property to true. If another control or some other action alters the contents of the multi-line text box, you can make sure that this property reflects the change. You can change this programmatically as follows: private void btnModified_Click(object sender, System.EventArgs e)
{
this.textBox1.Modified = true;
}
The multi-line text box allows the user to enter up to 32767 characters. If you want to limit the maximum number of characters that the user can enter to a value lower than this, you can use the MaxLength property at design time. You can also change this programmatically. Here is an example: private void btnModified_Click(object sender, System.EventArgs e)
{
this.textBox1.MaxLength = 1020;
}
If the control will be used to enter text, the user can press Enter at the end of a line to move to the next line. This ability is controlled by the Boolean AcceptsReturn property. By default, this property is set to False because this control is primarily created from a normal single-line TextBox control that has no formal action to take when the user presses Enter. If you are creating a multi-line text box and you expect your users to perform some type of text editing, you certainly should allow them to press Enter to move to the next line. Therefore, in most cases, when creating a multi-line text box, you should set its AcceptsReturn property to True. To set it programmatically, assign the desired value to the AcceptstReturn property. Here is an example: private void btnModified_Click(object sender, System.EventArgs e)
{
this.txtMemo.AcceptsReturn = true;
}
The user is accustomed to pressing Tab to insert tab characters in the text. By default, when the user presses Tab when interacting with your application, the focus moves from one control to the next, following the TabIndex values of the form. Even when using a multi-line text box to perform text editing, if the user presses Tab, the focus would switch to another control or to the form. If you want a multi-line text box to receive focus when the user presses the Tab key, set the AcceptTab property from False (the default), to True.
When entering text in a multi-line text box control, the characters start on the left side of the multi-line text box and are subsequently added on the right side. The ability to align text is controlled by the TextAlign property. For a multi-line text box control, the alignment is configured using the HorizontalAlignment enumerator.
As the user enters text in a multi-line text box box, the compiler considers that a paragraph starts from the user typing a character until he or she presses Enter. Therefore, a paragraph could be an empty space, a character, a word, a line of text, a whole page or an entire book. Depending on the width of the multi-line text box control, the text is incrementally added to the right side of each previous character. If the caret gets to the right border of the control, the text automatically continues to the next line, although it is still considered as one paragraph. To start a new paragraph, the user has to press Enter. The ability for the text to continue on the next line when the caret encounters the right border of the multi-line text box is controlled by the WordWrap property whose default Boolean value is set to true. If you do not want text to wrap to the subsequent line, set the WordWrap property to false. You can also set it programmatically as follows: private void btnModified_Click(object sender, System.EventArgs e)
{
this.txtMemo.AcceptsReturn = true;
this.txtMemo.WordWrap = false;
}
METHODS TO MANAGE THE MULTILINE TEXTBOX:-
The multi-line text box control is based on the TextBox class. To dynamically create a multi-line text box, declare a TextBox variable and use its default constructor to initialize it. The other operations the user can perform on a multi-line text box can be controlled by methods such as Undo(), Cut(), Copy(), Paste(), Clear() or SelectAll() that we reviewed for the text box control and they function the same.
SHORT METHOD:-
Short method is to choose the properties of a text box and choose textbox type and choose the multiline .

C# LABEL CONTROLS

INTRODUCTION:-



A label is a control that serves as a guide to the user. It provides static text that the user cannot change but can read to get information on a form. The programmer can also use it to display simple information to the user. Most controls on the form are not explicit at first glance and the user may not know what they are used for. Therefore, you can assign a label to a control as a help to the user.
To add a label to a container, click the Label button from the Toolbox and click the object that would host it. You can also dynamically create a label. A label is based on the Label class that is based on the Control class.


CHARACTERISTICS OF A LABEL:-

The most important characteristic of a label control is the text it displays. This is what the user would read. The text of a label is its Text property and is its default. To set a label’s caption, after adding the control to a container, click Text in the Properties window and type the desired value. As we mentioned when studying controls characteristics, at design time, the text you type in the Text field is considered “as is”. If you want to create a more elaborate and formatted string, you would have to do it programmatically.
After adding a label to a form, by default, it receives a fixed size. If you type its caption and press Enter, the text you provided would be confined to the allocated dimensions of the control. If the text is too long, part of it may disappear. You can then resize the label to provide more area. Another solution is to automatically resize the label to accommodate the length of the string you typed. This is aspects is controlled by the Boolean AutoSize property. Its default value is False. If you set this property to True, a rectangular border appears around it. If you type a string in the Text field and press Enter, the control would be resize to show the whole string but using only the necessary space.
Before or after typing the caption of a label whose AutoSize property is set to False, you can resize its allocated space to your liking. This is because a string occupies a rectangular area.


To click label and choose properties and choose text align to set:-

CODING:-

Label1.Text = " WINDOW FORM";

To joining Text

Label1.Text +="WINDOW FORM";

C# CONTROLS BUTTON










INTRO:-
A Button is a Windows control used to initiate an action. From the user’s standpoint, a button is useful when clicked, in which case the user positions the mouse on it and presses one of the mouse’s buttons. In some programming environments, the classic button is called a command button. There are other controls that can serve as click controls and initiate the same behavior as if a button were clicked. From the programmer’s standpoint, a button needs a host or container. The container could be a form, a toolbar, etc.

The most popular button used in Windows applications is a rectangular control that displays a word or a short sentence that directs the user to access, dismiss, initiate an action or a suite of actions. In .Net applications, this control is implemented using the Button control from the Toolbox. Therefore, to add a button to a container, click the Button control and click on the container, which is usually a form. Once you have added the control to your application, you can set its properties using the Properties window. The Button control is implemented by the Button class. The class ancestor of button of the .NET Framework is called ButtonBase. Therefore, to programmatically create a button, you can declare a variable of type Button. Here is an example:




using System;
using System.Drawing;
using System.Windows.Forms;
class Exercise : Form
{
Button btnResume;
public Exercise()
{
this.InitializeComponent();
}
private void InitializeComponent()
{
btnResume = new Button();
btnResume.Location = new Point(32, 20);

this.Controls.Add(btnResume);
}
static void Main()
{
Application.Run(new Exercise());
}
}

CHARACTERISTICS OF A BUTTON:-

For a user, the most important aspects of a button are the message it displays and the action it performs. Therefore, the default property of a button is the Text: this is the word or group of words that displays on top of the control, showing the message that would direct the user as to what the button is used for.
The most popular strings that buttons display are OK and Cancel. The OK caption is set for a form or a dialog box that informs the user of an error, an intermediary situation, or an acknowledgement of an action that was performed on the dialog that hosts the button. The Cancel caption is useful on a button whose main parent (the form or the dialog box) would ask a question or request a follow-up action from the user. Whenever a dialog box allows the user to dismiss it without continuing the action, you should provide a button with a Cancel caption.
If you create a dialog box with more than one button, you should designate one of them as the default. A default button is one that would apply its behavior if the user presses Enter after using it. Most of the time, a default button has a thicker border.
After adding a button to a form (by design or with code), you can change its caption with code by assigning the desired string to the Text property. For example, you can change the caption of a button as follows:



button1.Text = "Let it Go!";


After specifying the Text of a button, by default, it's positioned in the middle center of the button:



private void InitializeComponent()
{
btnResume = new Button();
btnResume.Text = "Resume";
btnResume.Location = new Point(32, 20);
btnResume.Size = new System.Drawing.Size(120, 48);
btnResume.TextAlign = ContentAlignment.BottomCenter;

this.Controls.Add(btnResume);
}




----------


private void InitializeComponent()
{
btnResume = new Button();
btnResume.Text = "Resume";
btnResume.Location = new Point(32, 20);
btnResume.Size = new System.Drawing.Size(120, 48);
btnResume.Image = Image.FromFile("C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\Graphics\\icons\\Office\\CRDFLE12.ICO");
btnResume.TextAlign = ContentAlignment.BottomCenter;

this.Controls.Add(btnResume);
}



After specifying the image for the button, you can use the ImageAlign property to specify the alignment of the image with regards to the Text of the button. You can do this at design time in the Properties window or programmatically as follows:



-----------



private void InitializeComponent()
{
btnResume = new Button();
btnResume.Text = "Resume";
btnResume.Location = new Point(32, 20);
btnResume.Size = new System.Drawing.Size(120, 48);
btnResume.Image = Image.FromFile("C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\Graphics\\icons\\Office\\CRDFLE12.ICO");
btnResume.ImageAlign = ContentAlignment.TopCenter;
btnResume.TextAlign = ContentAlignment.BottomCenter;

this.Controls.Add(btnResume);
}



Instead of using the Image property, you can first create an image list and add some pictures to it. Then, using the ImageList property, assign it to the button. Use the ImageIndex property to specify what picture would be displayed on the button.
After assigning a bitmap to the button, by default, it is positioned in the middle center of the button. If the button is not equipped with a caption, this position can be ideal. If you are using both the caption and the picture, you can use the ImageAlign property, possibly in combination with the TextAlign property, to specify how the picture would be positioned with regards to the caption. The ImageAlign property also is based on the ContentAlignment enumerator.
A regular button displays with raised borders as originally set by the operating system. To give your button a fancy look and behavior, you can use the FlatStyle property. The FlatStyle property is based on an enumerator of the same name. It provides 4 values that are:







  • Flat: The button appears flat. When the mouse is over it, it becomes highlighted




  • Popup: The button appears flat. When the mouse is over it, the borders of the button are raised




  • Standard: The buttons appears and behave like all regular buttons you have seen




  • System: The appearance of the button depends on the operating system using it



When the user clicks a button to close a dialog box, you must always know what button was clicked. The .NET Framework provides a mechanism to help identify such a button. This is done through the DialogResult property. This property is based on the DialogResult enumerator. To set the desired value, after adding a button to a dialog box and while the button is selected, in the Properties window, click the DialogResult field and select the desired value. The possible values of this property are: None, OK, Cancel, Abort, Retry, Ignore, Yes, and No.



BUTTON EVENTS:-

Obviously the most important and the most intuitive event of a button occurs when clicked. This event is of type EventArgs, which indicates that it doesn't provide nor does it need any formal details about what is going on. To launch this event, you can double-click the button on the form. To create this event programmatically, first implement the method that would carry its assignment, then increment-add (with the += operator) it to the Click property of the button by assigning it the EventHandler constructor. Here is an example:



using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
class Exercise : Form
{
Button btnResume;
public Exercise()
{
this.InitializeComponent();
}
private void InitializeComponent()
{
btnResume = new Button();
btnResume.Text = "Resume";
btnResume.Location = new Point(32, 20);
btnResume.Size = new System.Drawing.Size(120, 48);
btnResume.Image = Image.FromFile("C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\Graphics\\icons\\Office\\CRDFLE12.ICO");
btnResume.ImageAlign = ContentAlignment.TopCenter;
btnResume.TextAlign = ContentAlignment.BottomCenter;

btnResume.Click += new EventHandler(btnResume_Click);
this.Controls.Add(btnResume);
}
private void btnResume_Click(object sender, EventArgs e)
{
MessageBox.Show("Your employment application appear to be incomplete" +
"\nPlease complete it first before clicking Resume");
}
static void Main()
{
Application.Run(new Exercise());
}
}