Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2008, 10:29 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default btnClick Event Help

how do i make my btnSendData_Click() method recieve variables such as strings, or int's from the method that called it? if i tweak the arguement list the compiler complains.

 
Old April 4th, 2008, 10:38 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It depends.

A button's click event has this signature:

protected void btnClick(object sender, EventArgs e) and that can't be changed. Normally if you want to access some sort of data from the UI you would do something like:

protected void btnClick(object sender, EventArgs e)
{
    string foo = <mycontrol>.Text;
}

This, of course, assumes the control has a Text property. It would go a long well to explain a little more in detail what you are trying to do.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 4th, 2008, 11:57 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can always create your own Event Args class, using the EventsArgs as a base, and then pass that to it?

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old April 4th, 2008, 12:20 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You could do that but I believe you would have to also create a custom button control as well since, by default, the button click event doesn't pass any EventArgs.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 4th, 2008, 03:54 PM
Authorized User
 
Join Date: May 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to notrosh
Default

You could always create your own class using Button as your base class. Add a static event to that class with your own eventargs. Then override the onClick() in the Button class and invoke your event with your Eventargs. Then subscribe to that event in your main form.

-zd
 
Old April 5th, 2008, 05:50 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

if you want to use your own EventArgs, then you will need to create a custom button control that inherits from Button.

That Ladies and Gents, is a "hat trick" ;)

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Event - Sender & Event args dash dev C# 2005 9 December 9th, 2007 07:24 AM
first event bostek Excel VBA 2 September 7th, 2006 02:13 AM
What Event Exactly? Macsood ASP.NET 1.0 and 1.1 Basics 6 October 26th, 2005 09:24 AM
About Button event and Keydown event zhangxujun1981 XSLT 1 March 6th, 2004 04:59 AM
how to override an event with an event? blah VB.NET 2002/2003 Basics 5 November 13th, 2003 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.