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.
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 the info I only inserted the following lines:
Code:
DialogResult dr = new DialogResult();
LicenseAgreement LA = new LicenseAgreement();
dr = LA.ShowDialog();
if (dr == DialogResult.OK)
MessageBox.Show("User clicked OK button");
else if (dr == DialogResult.Cancel)
MessageBox.Show("User clicked Cancel button");
thanks!
G.
To Admin Please remove the duplicate post!!
Last edited by TBBW; November 30th, 2012 at 01:14 PM.
Reason: Duplicate Post removal
I am not entirely sure I follow. However, I think DialogResult might be helpful: http://www.dotnetperls.com/dialogresult If so, great! If not, push back an we'll try to help you some more.
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
This is probably a better way to test which object is the sender rather than ==
if (object.ReferenceEquals(sender, button6 ) )
MessageBox.Show (sender.ToString());
else if (object.ReferenceEquals(sender, button7 ) )
MessageBox.Show (sender.ToString());
Curt
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).
Last edited by TheGreatCthulhu; December 5th, 2012 at 04:31 AM.
First, for some strange reason there is a duplicate post, please do not reply to that one !!
As I mentioned in the parrallel post I only use these short snip
Code:
DialogResult dr = new DialogResult();
LicenseAgreement LA = new LicenseAgreement();
dr = LA.ShowDialog();
if (dr == DialogResult.OK)
MessageBox.Show("User clicked OK button");
else
MessageBox.Show("User clicked Cancel button");
Works Super!!
awaiting your comments.
regards,
Gerwin
Last edited by TBBW; December 5th, 2012 at 07:10 AM.
Reason: code correction
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks