naming controls

  • Thread starter Thread starter Tonya
  • Start date Start date
T

Tonya

Hi,

i am a beginner to vb.net and wanted to know how i can
use the same control with the same name and function in
the same form.

I.e if i want to have 4 save buttons on the same form and
name the the same........ is this poss. i dont wanna keep
coming up with new names for buttons that do the same
thing.

thx
 
Hi,

Since each button will be a separate instance of the Button class, and each
instance presumably have scope within the form you will have to give each
button a different name.

Hope this helps

Chris Taylor
 
You have to use different names, but you can at least use the same event
handlers.

cmdSave.Click += new System.EventHandler(Save_Click);
mnuSave.Click += new System.EventHandler(Save_Click);

Sorry for the C#.

HTH;
Eric Cadwell
http://www.origincontrols.com
 
Hi,
You can NOT use the same name on more than one control in
the same form. Yes, you can use the same event procedures
for multiple controls. There are more than one way to do
this. I will give you the easiest approach:
1. Put code in the event procedure (I suspect you are
using the Click event) that you want for one of the
controls.
2. For all controls that are to use the same code, you
can add on the control and event name in the handles
clause of the event procedure:

Private Sub cmdSave_Click(byVal Sender as Object, ByVal e
as system.eventargs) handles cmdSave.Click,
cmdSave2.Click, cmdSave3.Click

In the above sample, the event procedure will run when the
click event occurs for all three controls.

Now, if you have some differences in code based on which
control actually received the event, you will need to
check the Sender object to examine which control and then
do the appropriate action that is specific to the actual
control that received the event. I suspect you do not
need to apply this code as yet. If you do, ask, and you
will receive.

I hope this helps. My email address has only 2 "k"s in
it. Carol
 
Back
Top