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 / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

control questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Analizer1 - 03 Mar 2008 22:04 GMT
Hi hows it going

ive made dynamic buttons and added a button click event

ButtonClick(object sender,eventargs e)

Im sending all the Buttons created 1 to 3
I dont know how to get which button was clicked

thanks
Peter Duniho - 03 Mar 2008 22:12 GMT
> Hi hows it going
>
[quoted text clipped - 4 lines]
> Im sending all the Buttons created 1 to 3
> I dont know how to get which button was clicked

The "sender" parameter is a reference to the control instance that  
generated the click.  If you want the Button itself, you can just cast  
that to the Button type, or if all you need is something from the base  
Control class (e.g. the Tag property, commonly used to associate data with  
a particular control), just cast it to the Control type.

You can even just compare the reference to your class variables that  
reference each button (e.g. "button1", "button2", etc.).  IMHO this is the  
least preferable way to handle special-case behavior for a given button in  
a shared handler, but for small numbers of buttons it's not actually all  
that bad.

Finally, it probably goes without saying, but if you have drastically  
different behavior in the handler depending on which button is clicked,  
it's better to just have a different handler for each button.

Pete
Analizer1 - 03 Mar 2008 23:58 GMT
There is no Work in the handler..just figure out what
button was clicked set a public property to the button number and close the
window..

its just a generic message box

thanks alot for the answer

>> Hi hows it going
>>
[quoted text clipped - 22 lines]
>
> Pete
Peter Duniho - 04 Mar 2008 00:10 GMT
> There is no Work in the handler..just figure out what
> button was clicked set a public property to the button number and close  
> the
> window..

That's a self-contradictory statement.  First, if there's no work in the  
handler, why have it?

But more significantly, the steps "figure out what button was clicked",  
"set a public property to the button number", and "close the window" all  
represent some work.  So, assuming your handler does those things, there  
is definitely "work" in the handler.

> its just a generic message box

The answer would be the same, no matter what kind of form the button is  
contained in.

> thanks alot for the answer

You're welcome.

Pete
Analizer1 - 04 Mar 2008 00:58 GMT
I have to set a property so when the window closes
the programmer using the class knows what button was clicked

>> There is no Work in the handler..just figure out what
>> button was clicked set a public property to the button number and close
[quoted text clipped - 19 lines]
>
> Pete

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.