PROKA Posted April 21, 2004 Posted April 21, 2004 I have a sub "Button1_Click" Handling Button1.Click can I call this sub ? For example if I click on another button, I want to use the code Call Button1_Click(?) but where "?" is I need to parse in some arguments : ByVal sender As Object, ByVal e As System.EventArgs How do I do that ? Quote Development & Research Department @ Elven Soft
Joe Mamma Posted April 21, 2004 Posted April 21, 2004 I have a sub "Button1_Click" Handling Button1.Click can I call this sub ? For example if I click on another button, I want to use the code Call Button1_Click(?) but where "?" is I need to parse in some arguments : ByVal sender As Object, ByVal e As System.EventArgs How do I do that ? this is why VB is simply awful. In C# you just associate the same on onclick handler with every button that you want to use it. easy to do, straight forward and alot less user code cluttering up your project. I believe in vb you just do this Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Button1_Click(Button2, e) End Sub in c#, you wouldnt have to write any code, just associate the event using the property window Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
wessamzeidan Posted April 21, 2004 Posted April 21, 2004 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click,Button1.Click 'your code End Sub Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
iebidan Posted April 21, 2004 Posted April 21, 2004 Well actually Joe Mamma, you can do the same in VB, and in C# if you want associate the code with an event you need to add the += new EventHandler blah blah blah, so, it's the same, just in diff ways. And if you with writting less code, in VB you end up adding less code than in C# Quote Fat kids are harder to kidnap
PROKA Posted April 21, 2004 Author Posted April 21, 2004 if to compare VB6 and VC++ 6 yeah VB kinda sux , but VB.NET is as good as C# and vice-versa. Right ? Quote Development & Research Department @ Elven Soft
Joe Mamma Posted April 22, 2004 Posted April 22, 2004 Well actually Joe Mamma, you can do the same in VB, and in C# if you want associate the code with an event you need to add the += new EventHandler blah blah blah, so, it's the same, just in diff ways. And if you with writting less code, in VB you end up adding less code than in C# but I cant do it in the IDE by setting a property can I? I actually have to go in and write the '+=' which means switching between FormDesign and Code Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
PROKA Posted April 22, 2004 Author Posted April 22, 2004 :))))))))))))))))))))))))))))))))))))))))))))))))))))))) the energy to reply here would haved been enough for the next 100 switches Quote Development & Research Department @ Elven Soft
*Experts* Bucky Posted April 22, 2004 *Experts* Posted April 22, 2004 I have a sub "Button1_Click" Handling Button1.Click can I call this sub ? For example if I click on another button, I want to use the code Call Button1_Click(?) but where "?" is I need to parse in some arguments : ByVal sender As Object, ByVal e As System.EventArgs How do I do that ? To answer your question (I assume the question is still standing), you can pass whatever you like in the parameters. If you're not using them within the sub, then just pass Nothing to the sender and a new instance of the EventArgs class to e. Button1_Click(null, New EventArgs()) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Joe Mamma Posted April 22, 2004 Posted April 22, 2004 To answer your question (I assume the question is still standing), you can pass whatever you like in the parameters. If you're not using them within the sub, then just pass Nothing to the sender and a new instance of the EventArgs class to e. Button1_Click(null, New EventArgs()) if in a handler you will want to send the event args that were initially sent into the handler and the object generating the event as the sender Button1_Click(sender, e) that way Button1_Click can refernece the sending object and the event state Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Uncle Gizmo Posted April 26, 2004 Posted April 26, 2004 Call load event? Right, I'm doing the same, only slightly differently! I want to call the load event from a command button, is this possible? And if so how would I go about it please. I have used the above examples to make one command button perform another command buttons function, but when I tried it on the load event I got an error. Quote
*Experts* Bucky Posted April 27, 2004 *Experts* Posted April 27, 2004 You shouldn't have any problem with calling the Load event; it has the same parameters as a button's Click event (sender as Object, e As EventArgs). Could you tell us the error you're getting? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Uncle Gizmo Posted April 27, 2004 Posted April 27, 2004 Well I don�t know what�s going on I�ve had another bash at it tonight and it works OK�.. Must have been tired and made a mistake, This is the code for the button that closes the form: Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub And this test button now calls the button above Private Sub btnReset_Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click btnExit_Click(btnReset, e) End Sub I also tried this and it works OK. Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click frmPizza_Load(sender, e) End Sub And it also works OK in this format: Private Sub btnReset_Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click frmPizza_Load(btnReset, e) End Sub Are either of the last two above more correct than the other or are they both equally as good? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.