If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How to check which button was pressed

Hi all,

I have a Main Dialog it has 3 buttons; Install, Support and Exit
When the Install button is pressed a License Agreement Dialog is opened using .ShowDialog();
This Dialog has two buttons Install and Cancel.
(The Install button is enabled using two radio buttons (accept and do not accept))

But I use Close(); on both the Cancel and the Install button.
So back in the main menu I need to know if the Install button was presssed or if the cancel button was hit.
I can use a global int or bool flag, but that is not C# like.

Re: How to check which button was pressed

The License Agreement Dialog is made by you? If so, provide a public get-only property on your dialog class that would return an indicator of type DialogResult, and set it to either DialogResult.OK or DialogResult.Cancel from within the button handlers. Then you can check this property when the dialog is closed. Other dialogs available in the library use this method, and the property is usually called DialogResult itself - something like this:DialogResult DialogResult { get; private set; }

Thanks for contributing, but that can't be done as the buttons which are raising the evens are encapsulated inside a different form (a dialog), so they are not accessible (and are out of scope, since the dialog is closed). Anyway, this is an accidental duplicate thread, the question has already been resolved here, using the DialogResult enumeration - as suggested by
BioPhysEngr in the post above (which is a standard way to get this kind of info from a dialog).

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.