Dialog return values

Posted on 2004-11-11
Last Modified: 2010-04-15

I created a modal dialog with OK and Cancel buttons.  Inside the dialog, I call the Close() function to close the dialog.  But when I inspect the return value (see code below), it comes back as Cancel, even though I clicked on the OK button.

Password pwDlg = new Password();
System.Windows.Forms.DialogResult reply = pwDlg.ShowDialog(this);
if ( reply == System.Windows.Forms.DialogResult.OK )
    // do something

By this I mean that the value of the reply variable is "Cancel".

Am I missing something?  Should I be associating a button object with the some property so this built-in functionality works?

Thanks for the help.
Question by:ba272
    LVL 6

    Accepted Solution

    In the Dialog from(Password form), select the Kk button and set its DialogResult property to Ok. Like that for Cancel button set its DialogResult property to Cancel.
    LVL 6

    Expert Comment

    Oops.. not KK, Ok. Sorry for that...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now