Display MessageBox in Button event : MessageBox : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » MessageBox »

 

Display MessageBox in Button event









    
using  System;  
using  System.Windows.Forms;  
using  System.Drawing;  
  
class  ButtonEventMessageBox  :  Form  {  
    Button  StopButton;  
  
    public  ButtonEventMessageBox()  {  
        Text  =  "Adding  a  Stop  Button";  
  
        StopButton  =  new  Button();  
        StopButton.Text  =  "Stop";  
        StopButton.Location  =  new  Point(100,  100);  
  
        StopButton.Click  +=  StopButtonClick;  
        Controls.Add(StopButton);  
    }      
  
    [STAThread]  
    public  static  void  Main()  {  
        ButtonEventMessageBox  skel  =  new  ButtonEventMessageBox();  
  
        Application.Run(skel);  
    }  
  
    protected  void  StopButtonClick(object  who,  EventArgs  e)  {  
        DialogResult  result  =  MessageBox.Show("Stop  Program?",  
                                                        "Terminate",  
                                                        MessageBoxButtons.YesNo);  
  
        if(result  ==  DialogResult.Yes)  
                Application.Exit();  
    }  
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» MessageBox