Saturday, August 11, 2012

Read textbox Buttons C#


   1:  private void BtnClick_Click(object sender, EventArgs e)
   2:    {
   3:      DialogResult Result;
   4:      Result = MessageBox.Show("Do you like my blog ? ", "Question", MessageBoxButtons.YesNo);
   5:        if (Result == DialogResult.Yes)
   6:           {
   7:               MessageBox.Show("You clicked on Yes :) ");
   8:           }
   9:         else if (Result == DialogResult.No)
  10:           {
  11:               MessageBox.Show("You clicked on NO  :( ");
  12:           }
  13:    }

In the above code
1. I have created a variable of DialogResult, (this variable will be use to store/identify which button did user press)

2. Than on line 5 we compare if the value in result variable equals to DialogResult.Yes than press

"You clicked on Yes"

Else

"You Click on No"

I hope this was informative for you, and I would like to thank you for reading.

No comments:

Post a Comment