473,395 Members | 1,581 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,395 software developers and data experts.

VB-> Button #1 do the same as #2

I want to make button1_click do the same as button2_click WITHOUT wrtiting
the exact code all over....

I was thinking of something like (button2 = button1)....obviously that
doesnt work...so....can anyone help???
Nov 21 '05 #1
6 1326
Hareth,

This one is simple, in sub from the button2_click event you can add at the
end
handles button1.click, button2.click

I hope this helps,

Cor

"Hareth" <ab******@hotmail.com> ..
I want to make button1_click do the same as button2_click WITHOUT wrtiting
the exact code all over....

I was thinking of something like (button2 = button1)....obviously that
doesnt work...so....can anyone help???

Nov 21 '05 #2
I got a "Syntax Error" message
Nov 21 '05 #3
"Hareth" <ab******@hotmail.com> schrieb:
I got a "Syntax Error" message


Post your code.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4
Reply: If you want to associate a different Event handler with the same
event use RemoveHandler Statement to disassociate the event with the current
event handler and use the AddHandler statement to associate it with a
different event handler. In my example I used a button control that was used
to start and stop a process. The bulk of the code was in the StopProcess
event:

TextBox1.Text = "Process Complete"
btnStopStart.Text = "Start"
RemoveHandler btnStopStart.Click.AddressOf StopProcess
AddHandler btnStopStart.Click, AddressOf StartProcess

The other code consisted of one line in the Form1 and the StartProcess events.

"Hareth" wrote:
I want to make button1_click do the same as button2_click WITHOUT wrtiting
the exact code all over....

I was thinking of something like (button2 = button1)....obviously that
doesnt work...so....can anyone help???

Nov 21 '05 #5
JAW
Why not just create a subroutine that is called by both button clicks ?

sub buttion1_click ()
dosomething ()
end sub

sub button2_click ()
dosomething ()
end sub

sub dosomething ()

end sub

HTH
Jerry

Hareth wrote:
I want to make button1_click do the same as button2_click WITHOUT wrtiting
the exact code all over....

I was thinking of something like (button2 = button1)....obviously that
doesnt work...so....can anyone help???

Nov 21 '05 #6
The "Handles" keyword lets you wire one or more events to a method. In the
code below, the Button_Click sub will be called when the user clicks Button1
or Button2.
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click, Button2.Click

End Sub

- Scott Swigart

"JAW" <yo*****@noserver.com> wrote in message
news:9j**************@fe1.columbus.rr.com...
Why not just create a subroutine that is called by both button clicks ?

sub buttion1_click ()
dosomething () end sub

sub button2_click ()
dosomething ()
end sub

sub dosomething ()

end sub

HTH
Jerry

Hareth wrote:
I want to make button1_click do the same as button2_click WITHOUT
wrtiting the exact code all over....

I was thinking of something like (button2 = button1)....obviously that
doesnt work...so....can anyone help???

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Terry | last post by:
Hi, I need some feedback. We are converting to .Net and we are trying to decide on whether to use VB.net or C#.net. As far as our current systems, they will probably be rewritten in ASP.Net. I...
7
by: Simon Peng | last post by:
-- ---------------- Simon Peng xqpeng@tsinghua.org.cn
5
by: Saga | last post by:
Hi all, I just read the thread by the same name posted on Jun 15, 9:45 AM, but I am looking at it from a different point of view. I came across this question in terms of functionality. Are VB and...
13
by: Arsalan | last post by:
Is there any advantage in C# over VB.NET ? Or the difference is only syntax ? Can anything done in C# which cannot be done in VB.NET?
72
by: Robin Tucker | last post by:
I need to find some documents/research for my manager about VB.NET v C# use. I've noticed that there are many more people using C# than VB.NET, that there seem to be more job vacancies specifying...
28
by: Andy | last post by:
Any good resources regarding benefitis by using C3 over VB? /Andy
34
by: Eric Wise | last post by:
Does anyone work for companies that actually implement both VB and C#? I know that you can do this in theory, I just find it hard to imagine that a company would split its programming technologies...
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
25
by: Sharrukin Amiri | last post by:
Hello, I am using VB 6.0 for many years. Everytime I needed to build software applications, I just opened VB 6.0 and started coding. I am now looking VB.NET Express Edition and I find I can no...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.