473,395 Members | 1,411 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.

Why not work?

YXQ
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("ssss")
End Sub

Private Sub eee()
AddHandler Button1.Click, AddressOf Button1_Click
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
eee()
End Sub
*******************************************
Why the codes will not work? Thank you!
Nov 21 '05 #1
3 1049

"YXQ" <ga***@163.com> wrote in message news:uE**************@TK2MSFTNGP12.phx.gbl...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("ssss")
End Sub

Private Sub eee()
AddHandler Button1.Click, AddressOf Button1_Click
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
eee()
End Sub
*******************************************
Why the codes will not work? Thank you!


Theres nothing wrong with the code. But if you are expecting a message box to be displayed upon
clicking button 2 then you misunderstand the
AddHandler event hook up.

hth
Richard
Nov 21 '05 #2
YXQ,

It is easier to make this code like this

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click, Button2.Click
MessageBox.Show("ssss")
End Sub
Why the codes will not work? Thank you!


As Richard said, your code works, however it does nothing.

Cor
Nov 21 '05 #3
YXQ,
In addition to the other comments, if you are expecting the message box to
be displayed when eee is called. Then you need to use Button1.PerformClick
instead of AddHandler.

AddHandler adds an event handler to the list of event handlers, it does not
invoke said handler.
Private Sub eee()
Button1.PerformClick
End Sub
NOTE: Only selected controls expose methods such as PerformClick that you
can call to have their events raised.

Hope this helps
Jay

"YXQ" <ga***@163.com> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("ssss")
End Sub

Private Sub eee()
AddHandler Button1.Click, AddressOf Button1_Click
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
eee()
End Sub
*******************************************
Why the codes will not work? Thank you!

Nov 21 '05 #4

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

Similar topics

7
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
3
by: Douglas Buchanan | last post by:
Buttons don't work if form is opened on startup A2k If 'frmMain' is set to open by default at startup none of the buttons work. If 'frmMain' is opened from the database window then all the...
15
by: Brett | last post by:
I'd like to know what management and the work environment are like where you work. I need something relative to compare my current work environment. Here's a few questions I have: 1.) Is it...
2
by: Holysmoke | last post by:
Hi, I have a asp.net form with a button in it. In the onlclick event of button I want to write a function which does some a bit of work with a timespan of 15 seconds. So I want to show a image...
1
by: Jeff | last post by:
Hello, I have developed a library of controls but for the life of me cannot get ToolboxBitmapAttribute to work -- my image simply will not display in the toolbox of any project using my...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
33
by: bonk | last post by:
I have an application that needs to perform some background work, i.e. Logging, wich must not block the main thread. How would I basically design such a scenario? It is obvious that I should do...
11
Niheel
by: Niheel | last post by:
http://bytes.com/images/howtos/information_overloaded.jpgPaul Graham wrote an interesting article a few months back about how the internet is leading to information overload for information workers...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.