Passing boolean value from one form to another form in C#

  • Thread starter Daniel Passwater via DotNetMonster.com
  • Start date
D

Daniel Passwater via DotNetMonster.com

I'm working on a C# multi-form app in the compact framework. The forms are called from a main menu that stays in the background. Since there is no yes/no MeassageBox in the compact framework, I'm displaying a third form as a secondary check of the user's intentions. (i.e. Are you sure that you want to do this?)
I am trying to pass the boolean value back to the form that opens the secondary check form. Could someone please tell how this might be done?

Thanks in advance for any and all help.
Daniel
 
W

William Stacey [MVP]

If it is dialog you could also test the DialogResult var.

--
William Stacey, MVP
http://mvp.support.microsoft.com

Daniel Passwater via DotNetMonster.com said:
I'm working on a C# multi-form app in the compact framework. The forms are
called from a main menu that stays in the background. Since there is no
yes/no MeassageBox in the compact framework, I'm displaying a third form as
a secondary check of the user's intentions. (i.e. Are you sure that you want
to do this?)
I am trying to pass the boolean value back to the form that opens the
secondary check form. Could someone please tell how this might be done?
 
S

Stu Smith

Daniel Passwater via DotNetMonster.com said:
I'm working on a C# multi-form app in the compact framework. The forms are
called from a main menu that stays in the background. Since there is no
yes/no MeassageBox in the compact framework, I'm displaying a third form as
a secondary check of the user's intentions. (i.e. Are you sure that you want
to do this?)
I am trying to pass the boolean value back to the form that opens the
secondary check form. Could someone please tell how this might be done?

Personally I never call ShowDialog form outside the form itself. (I think
it's a shame this method wasn't made protected).

I would use a pattern like this:

public class QuestionForm : Form
{
public bool Ask( Control owner, string question )
{
// Setup the form.
_questionLabel.Text = question;

// Show it.
switch( ShowDialog( owner ) )
{
case DialogResult.Yes:
return true;
default:
return false;
}
}
}

This way, the form can make sure it is set up correctly (ie you cannot
forget to set some message property before showing the form), and can accept
and return values in a more natural form (properties and dialog results
don't seem natural to me).

Stu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top