By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Buttons

P: n/a

hey guys ...

quick question ... i have two buttons (cmdButton1, cmdButton2) .... how do i use the click event in cmdButton1 from cmdButton2 ?

for example .. if you click cmdButton1 .. a massage box pops up saying "hello world" .. i wont to pop up this message box by click on cmdButton2 ..

I hope i make some sense !

NEED CODE PLEASE
THANX IN ADVANCE
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Oh my...

You probably have the followinf line of code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Add to the end of it the following: ,Button2.Click

(please do not forget the comma)

Telmo Sampaio

"Will" <Wi**@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...

hey guys ...

quick question ... i have two buttons (cmdButton1, cmdButton2) .... how do i use the click event in cmdButton1 from cmdButton2 ?
for example .. if you click cmdButton1 .. a massage box pops up saying "hello world" .. i wont to pop up this message box by click on cmdButton2 ..
I hope i make some sense !

NEED CODE PLEASE
THANX IN ADVANCE

Nov 20 '05 #2

P: n/a
* "=?Utf-8?B?V2lsbA==?=" <Wi**@discussions.microsoft.com> scripsit:
quick question ... i have two buttons (cmdButton1, cmdButton2) .... how do i use the click event in cmdButton1 from cmdButton2 ?

for example .. if you click cmdButton1 .. a massage box pops up saying "hello world" .. i wont to pop up this message box by click on cmdButton2 ..


I am not sure if I understand your question. Do you want to create a
'Click' event handler that is used by both buttons?

\\\
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
...
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

P: n/a
Will,

We understood you very clear. If you use the same procedure for handling
both events you can easily reproduce what you want. If you do not understand
the sender and e arguments you should do some research related to them and
to object oriented programming.

Here are some interesting links:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemWindowsFormsControlClassClickTopic.asp

Telmo Sampaio

"Will" <Wi**@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...

i dont think you guys understood me ... what i mean is if i click cmdButton1, a message pops up ("Hello World") ..
no if i try to call the me.cmdButton1_click event in cmdButton2, me.cmdbutton1_click(Sender as Object,e as System.eventArgs) how do i use
Sender as Object and the e as System.eventArgs ? what do they mean ?
THANX IN ADVANCE GUYS

"Herfried K. Wagner [MVP]" wrote:
* "=?Utf-8?B?V2lsbA==?=" <Wi**@discussions.microsoft.com> scripsit:
quick question ... i have two buttons (cmdButton1, cmdButton2) .... how do i use the click event in cmdButton1 from cmdButton2 ?
for example .. if you click cmdButton1 .. a massage box pops up saying
"hello world" .. i wont to pop up this message box by click on cmdButton2 ..
I am not sure if I understand your question. Do you want to create a
'Click' event handler that is used by both buttons?

\\\
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click ...
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4

P: n/a
> no if i try to call the me.cmdButton1_click event in cmdButton2

IMHO an event should fire *because it happened*. You should not be the one
calling cmdButton1_click. This is just bad conception...

--
Best Regards
Yanick Lefebvre
Nov 20 '05 #5

P: n/a
Example: Use Sender
Private Sub LableLeaveEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblBuyerBroker.MouseLeave
Dim strLabname As String = System.Convert.ToString(sender.Name())
Select Case strLabname
Case "lblBuyerBroker"
lblBuyerBroker.Cursor = Cursors.Default
End Select
End sub

Example: Use e
Private Sub NumbValidation_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUnitQty.KeyPress
If (Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar)) Or Char.IsPunctuation(e.KeyChar) Then
If e.KeyChar = Char.Parse("-") Or e.KeyChar = Char.Parse(".") Then
e.Handled = False
Else
e.Handled = True
End If
End If
End Sub
"Will" wrote:

i dont think you guys understood me ... what i mean is if i click cmdButton1, a message pops up ("Hello World") ..

no if i try to call the me.cmdButton1_click event in cmdButton2, me.cmdbutton1_click(Sender as Object,e as System.eventArgs) how do i use Sender as Object and the e as System.eventArgs ? what do they mean ?

THANX IN ADVANCE GUYS

"Herfried K. Wagner [MVP]" wrote:
* "=?Utf-8?B?V2lsbA==?=" <Wi**@discussions.microsoft.com> scripsit:
quick question ... i have two buttons (cmdButton1, cmdButton2) .... how do i use the click event in cmdButton1 from cmdButton2 ?

for example .. if you click cmdButton1 .. a massage box pops up saying "hello world" .. i wont to pop up this message box by click on cmdButton2 ..


I am not sure if I understand your question. Do you want to create a
'Click' event handler that is used by both buttons?

\\\
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
...
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #6

P: n/a
You can wire both click events to one procedure or not, but I would separate
out your logic from the button event itself. The benefit to this is that
you can call DoSomething from anywhere (not just these events).

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
DoSomething
End Sub

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

or simply....
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click, Button2.Click
DoSomething
End Sub

Private Sub DoSomething()
msgbox("Hello World")
End Sub

HTH,
Greg

"Will" <Wi**@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...

i dont think you guys understood me ... what i mean is if i click cmdButton1, a message pops up ("Hello World") ..
no if i try to call the me.cmdButton1_click event in cmdButton2, me.cmdbutton1_click(Sender as Object,e as System.eventArgs) how do i use
Sender as Object and the e as System.eventArgs ? what do they mean ?
THANX IN ADVANCE GUYS

"Herfried K. Wagner [MVP]" wrote:
* "=?Utf-8?B?V2lsbA==?=" <Wi**@discussions.microsoft.com> scripsit:
quick question ... i have two buttons (cmdButton1, cmdButton2) .... how do i use the click event in cmdButton1 from cmdButton2 ?
for example .. if you click cmdButton1 .. a massage box pops up saying
"hello world" .. i wont to pop up this message box by click on cmdButton2 ..
I am not sure if I understand your question. Do you want to create a
'Click' event handler that is used by both buttons?

\\\
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click ...
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7

P: n/a
"Will" <Wi**@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...

i dont think you guys understood me ... what i mean is if i click cmdButton1, a message pops up ("Hello World") ..
no if i try to call the me.cmdButton1_click event in cmdButton2, me.cmdbutton1_click(Sender as Object,e as System.eventArgs) how do i use
Sender as Object and the e as System.eventArgs ? what do they mean ?
THANX IN ADVANCE GUYS


Are you taking the Intro to VB.NET course on About.com by any chance?
Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.