Buttons and form show and close
-
yesb.Click += new System.EventHandler(this.Show()); nob.Click += new System.EventHandler(this.Close());
this is the error I keep getting:
An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()'
Same thing for this.Close() as well. I have two buttons, one should reload the application, and the other closes it. -
yesb.Click += new System.EventHandler(this.Show()); nob.Click += new System.EventHandler(this.Close());
this is the error I keep getting:
An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()'
Same thing for this.Close() as well. I have two buttons, one should reload the application, and the other closes it. -
Interesting Have you tried pressing TAB twice after writing the +=? Putting the show/close in those methods may be more.. reliable (as in: no chance that it could go wrong)
-
yesb.Click += new System.EventHandler(this.Show()); nob.Click += new System.EventHandler(this.Close());
this is the error I keep getting:
An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()'
Same thing for this.Close() as well. I have two buttons, one should reload the application, and the other closes it.You can't call Show or Close this way unless you overload the methods i.e
//Note: the parameters are defined by the delegate so no parenthesis
yesb.Click += new EventHandler(Show);void Show(object sender, EventArgs e)
{
Show();
}The normal way is to have a Click event handler and call Show from there - the same really - just a more logical name.
yesb.Click += new EventHandler(yesb_Click);
void yesb_Click(object sender, EventArgs e)
{
Show();
}Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
You can't call Show or Close this way unless you overload the methods i.e
//Note: the parameters are defined by the delegate so no parenthesis
yesb.Click += new EventHandler(Show);void Show(object sender, EventArgs e)
{
Show();
}The normal way is to have a Click event handler and call Show from there - the same really - just a more logical name.
yesb.Click += new EventHandler(yesb_Click);
void yesb_Click(object sender, EventArgs e)
{
Show();
}Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)