How to execute the button1_Click event in the other button's Click event or textBox1_TextChanged?
-
There are two buttons (Button1、Button2) and one TextBox in the winform,I have two questions as below: 1、I want to the execute the button1_Click event when clicking the button2_Click? 2、when the text of textbox1 is changed, then call the button1_Click event, how to write in the textBox1_TextChanged? thanks in advance,pls give the codes in detail. (Don't use this method: place all the codes of button1_Click in one method then use this method in button2_Click)
-
There are two buttons (Button1、Button2) and one TextBox in the winform,I have two questions as below: 1、I want to the execute the button1_Click event when clicking the button2_Click? 2、when the text of textbox1 is changed, then call the button1_Click event, how to write in the textBox1_TextChanged? thanks in advance,pls give the codes in detail. (Don't use this method: place all the codes of button1_Click in one method then use this method in button2_Click)
Hi, I know of 3 solutions: 1. put the logic in a simple method which gets called by all interested handlers, so have button1_Click and textBox1_TextChanged call the simple method; 2. call button1_Click() with 2 dummy arguments; maybe
null, null
is sufficient; maybethis, new EventArgs()
is needed. In both cases, they do not really carry much information. 3. some actions can easily be simulated, trybutton1.PerformClick()
Most of the time I prefer #1. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
Hi, I know of 3 solutions: 1. put the logic in a simple method which gets called by all interested handlers, so have button1_Click and textBox1_TextChanged call the simple method; 2. call button1_Click() with 2 dummy arguments; maybe
null, null
is sufficient; maybethis, new EventArgs()
is needed. In both cases, they do not really carry much information. 3. some actions can easily be simulated, trybutton1.PerformClick()
Most of the time I prefer #1. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
I often us the this.button_click(null, null). Commonly, these two parameters of the method of button_click are no use. :|
That's not the best method to do it. Luc's number 1 response is the best way to do it since the code you write in other places doesn't have to know that it's passing bogus parameters to a method that doesn't even require them.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...