Using buttons PDF Print E-mail

All kind of buttons can be used in a Windows application. The Button class can be used to implement these:

  1.  
  2. using System;
  3. using System.Windows.Forms;
  4. class ButtonSample : Form {
  5. public static void Main() {
  6. Application.Run( new ButtonSample() );
  7. }
  8. ButtonSample() {
  9. Button b = new Button();
  10. b.Parent = this;
  11. b.Text = "Click me";
  12. b.Click += new EventHandler( clickHandler );
  13. }
  14. void clickHandler( object o, EventArgs ea ) {
  15. MessageBox.Show( "You have clicked the button" );
  16. }
  17. }
 

In the constructor, we declare an object of type Button and we assign its Parent property to this (which means the ButtonSample object). We decide to label the button with the string "Click me" and we add an event handler to the Click event of the Button class.

A typical event handler takes two arguement, the first is a generic object and the other is an object of type EventArgs. The handler simply displays a message box.




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
 
< Prev   Next >
Joomla Template by Joomlashack
Joomla Templates by JoomlaShack Joomla Templates by Compass Design