Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

Button event handler

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne Garvander - 23 Jan 2008 02:06 GMT
I need to dunamically create buttons on a windows forms depending on the data
that is requested.
How can I create an event handler on the fly for this buttons?

Signature

Arne Garvander
Certified Geek
Professional Data Dude

Michael C - 23 Jan 2008 05:43 GMT
>I need to dunamically create buttons on a windows forms depending on the
>data
> that is requested.
> How can I create an event handler on the fly for this buttons?

This is it in C#, to convert to VB you add the word addressof inside the
brackets but I'm not sure what you do with the +=. Probably
MyButton.Click.AddSomething...

MyButton.Click += new EventHandler(FunctionToCall);

Michael
Jack Jackson - 23 Jan 2008 07:08 GMT
>I need to dunamically create buttons on a windows forms depending on the data
>that is requested.
>How can I create an event handler on the fly for this buttons?

dim btn as System.Windows.Forms.Button
...
btn = New System.Window.Forms.Button
Me.Controls.Add(btn)
Addhandler btn.Click, AddressOf ButtonClickHandler
...
Private Sub ButtonClickHandler(ByVal sender As System.Object, _
    ByVal e As System.EventArgs)

End Sub
Arne Garvander - 23 Jan 2008 14:16 GMT
Jack,
Thanks.
I need 1 to many buttons. Is there a way I can make all the buttons use the
same event handler?
Signature

Arne Garvander
Certified Geek
Professional Data Dude

> >I need to dunamically create buttons on a windows forms depending on the data
> >that is requested.
[quoted text clipped - 10 lines]
>
> End Sub
Herfried K. Wagner [MVP] - 23 Jan 2008 14:21 GMT
"Arne Garvander" <ArneGarvander@discussions.microsoft.com> schrieb:
> I need 1 to many buttons. Is there a way I can make all the buttons use
> the
> same event handler?

Yes, via 'AddHandler'.  Simply specify the same handling routine for the
buttons' events.

Inside the event handler the 'sender' parameter will contain a reference to
the control the event belongs to.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.