473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Buttons


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
7 1499
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
* "=?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
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
> 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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ralph Freshour | last post by:
Is it possible to inhibit the browser Back/Fwd buttons via PHP? Thanks...
4
by: Bob Lehmann | last post by:
Hi, I pretty sure I've seen this problem addressed before, but I can't find any references. The short story is that I have I have multiple submit buttons on a page, each providing different...
2
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, which has 4 command buttons: Sort Title (cmdSortTitle), Sort Name (cmdSortName), Due Today (cmdDueToday), and Due List (cmdDueList). Sort Title and Sort...
5
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main...
0
Denburt
by: Denburt | last post by:
This code is for a Toggle Button layout on a form, with this code you can set a number of toggle buttons visible and have multiple submenus that will stay hidden when not in use. My main menu is set...
4
by: Ron | last post by:
I want to create 10 buttons on a form at runtime, the code below is only creating one button labeled 1. Any idea what I am doing wrong? Public Class Form1 Public code(10) As String Public...
3
by: Ron | last post by:
Can anyone help me out? I am trying to add buttons numbered one through 10 at runtime to a form. I think they are getting added but they seem to be getting stacked one on top of each other. so...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
2
by: remya1000 | last post by:
hai i'm using Vb.net. i'm creating 64 dynamic created buttons of 8 rows and 8 columns. And i have 1 Go button, 1 textbox. those were created dynamically. if i enter one number inside textbox and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.