Results 1 to 3 of 3

Thread: escape key for a dailog result

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    91

    escape key for a dailog result

    hi

    i created a dialog result


    DialogResult Result = new DialogResult();
    Result = MessageBox.Show("Are you sure you want to show the screen?", "", MessageBoxButtons.YesNo);
    if (Result == DialogResult.Yes)
    {

    form2 f2=new form2();
    f2.show();
    }
    if (Result == DialogResult.No)
    {

    MessageBox.Show " you are in form1";
    }



    After getting confirmation message if i click escape button i should get the Result with "NO"

    how to capture DialogResult keydown event


    Regards
    Vinay Kumar

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: escape key for a dailog result

    Firstly, DialogResult is an enumeration. You don't use constructors to create enumerated values. Change this:
    c# Code:
    1. DialogResult Result = new DialogResult();
    to this:
    c# Code:
    1. DialogResult Result;
    Secondly, you're using the wrong buttons on your MessageBox. When you are asking the user to confirm an action that they've already asked for you don't use YesNo but rather OKCancel.

    Finally, only a Cancel button on a MessageBox gets clicked automatically when the user presses the Escape key. If your MessageBox is showing YesNo then the user has to click the No button themselves. Fortunately for you, you will be using OKCancel for the reason I specified above so the user can use the Escape key to click the Cancel button.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    91

    Re: escape key for a dailog result

    hi


    Thanks for the reply. i resolved the issue.

    thank u once again for helping me in resolving this issue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width