English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

ok so i have Buttton1 and Button2
Button1does something
i want Button2 to trigger the Button1 the same way as clicking Button1 would.

what do i type in:
Private Sub Button2_Click

to get it to click on button1

does this work? Is it possible? am i making sense?

PS: please be very simple with your code. i'm trying to teach myself and don't know much at all!

2007-06-20 10:00:15 · 2 answers · asked by Supreme Overlord 2 in Computers & Internet Programming & Design

2 answers

VB2005:

You can call another Buttons click event by calling the desired click event and providing the required parameters (Sender and e)

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call Button1_Click(sender, e)

End Sub

Even though this works I would consider this coding style in bad form.... EDIT: If this was done in a large program you would not really know what is intended when button2 event fires because it calls button1. You would have to search and look at button1's event

Consider:
Private Sub Button2_Click......
SaveFile("C:\myfileName.txt")
End Sub

By caling a proceedure givien a meaningful name (SaveFile) there is no doubt what you intend your code to do.

If you need to need to run code triggered by more than one event it is best to put that code into a seperate subroutine or function identified with a meaningful name .

Then button 1 & 2 click events call that function.

This will make your code easier to read

2007-06-20 12:23:33 · answer #1 · answered by MarkG 7 · 0 0

make a procedure, and make both buttons call the same procedure. simple and effective

2007-06-20 17:05:25 · answer #2 · answered by gunnar t 2 · 0 0

fedest.com, questions and answers