473,404 Members | 2,178 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,404 software developers and data experts.

Obtain Sender

how do i convert a sender into a Button type of component?
im doing so becoz i wanted to access some of the properties of the button
Feb 2 '06 #1
9 1396
Hello, nagen!

n> how do i convert a sender into a Button type of component?
n> im doing so becoz i wanted to access some of the properties of the
n> button

if you mean eventhandler parameter then
object sender;

Button button = sender as Button;
if ( button != null )
{
//access properties of the button
}

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 2 '06 #2
nagen wrote:
how do i convert a sender into a Button type of component?
im doing so becoz i wanted to access some of the properties of the button


if( sender is Button )
{
Button b = (Button) sender ;
}
else if( sender is SomethingElse )
{
SomethingElse se = (SomethingElse) sender ;
}
Feb 2 '06 #3
Hello, #!

C> nagen wrote:
??>> how do i convert a sender into a Button type of component?
??>> im doing so becoz i wanted to access some of the properties of the
??>> button

C> if( sender is Button )
C> {
C> Button b = (Button) sender ;
C> }
C> else if( sender is SomethingElse )
C> {
C> SomethingElse se = (SomethingElse) sender ;
C> }

This cast can introduce InvalidCastException if sender is of other type

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 2 '06 #4
Vadym Stetsyak wrote:
Hello, #!

C> nagen wrote:
??>> how do i convert a sender into a Button type of component?
??>> im doing so becoz i wanted to access some of the properties of the
??>> button

C> if( sender is Button )
C> {
C> Button b = (Button) sender ;
C> }
C> else if( sender is SomethingElse )
C> {
C> SomethingElse se = (SomethingElse) sender ;
C> }

This cast can introduce InvalidCastException if sender is of other type


Thank you for your correction.

Could you please, bring me more explanation :

The InvalidCastException should only occurs later in the explicits cast "Obj o2
= (Type) o1".
And it is protected by the "if( obj is Type)".

Isn't it ?

Cyrille
Feb 2 '06 #5
C> Thank you for your correction.

C> Could you please, bring me more explanation :

C> The InvalidCastException should only occurs later in the explicits cast
C> "Obj o2 = (Type) o1".
C> And it is protected by the "if( obj is Type)".

C> Isn't it ?

Yes, I agree with you. Somehow I've missed _is_ statement :8-)
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 2 '06 #6
Vadym Stetsyak wrote:
C> Thank you for your correction.

C> Could you please, bring me more explanation :

C> The InvalidCastException should only occurs later in the explicits cast
C> "Obj o2 = (Type) o1".
C> And it is protected by the "if( obj is Type)".

C> Isn't it ?

Yes, I agree with you. Somehow I've missed _is_ statement :8-)
Ouf! My code is not so bad ;o)

By the way ... I like the "if/else" cascading like that I can handle differents
senders with the same method.

cyrille
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Feb 2 '06 #7
Sorry im a little blur here could u give me the full working code...
with the correction

thank you

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Vadym Stetsyak wrote:
C> Thank you for your correction.

C> Could you please, bring me more explanation :

C> The InvalidCastException should only occurs later in the explicits
cast C> "Obj o2 = (Type) o1".
C> And it is protected by the "if( obj is Type)".

C> Isn't it ?

Yes, I agree with you. Somehow I've missed _is_ statement :8-)


Ouf! My code is not so bad ;o)

By the way ... I like the "if/else" cascading like that I can handle
differents senders with the same method.

cyrille
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Feb 3 '06 #8
What they are saying is to code it like this:

if( sender is Button )
{
Button b = (Button) sender ;
b.Text = "I have been clicked!";
}
This IF statement will only be entered into if the sender really is a
button, and not something else.
(Because sender is passed as type 'object' so it really could be
anything)

Feb 3 '06 #9
thank you everyone :-)

"Steven Nagy" <le*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
What they are saying is to code it like this:

if( sender is Button )
{
Button b = (Button) sender ;
b.Text = "I have been clicked!";
}
This IF statement will only be entered into if the sender really is a
button, and not something else.
(Because sender is passed as type 'object' so it really could be
anything)

Feb 4 '06 #10

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

Similar topics

7
by: Sam | last post by:
Hi, I can use System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() to obtain the path for ILASM.exe, but how can I obtain the path to ILDASM.exe? Examples of the path I'm...
5
by: Jeronimo Bertran | last post by:
Hello, We have developed a socket tcpip server in .net that accepts calls from clients. Using the connected socket we are able to use the Socket.RemoteEndPoint to obtain the IP address of the...
5
by: Kevin Myers | last post by:
How can one obtain obtain the height of a MS Access 2K form? There is a width property, but I don't see a corresponding height property. I need to obtain the height of the form so that I can...
2
by: Rodrigo C. Souza | last post by:
How to obtain the IP address of the interface that is connected to the Internet? I´m using the code below to get IP address of the local machine: //*********************************************...
3
by: ad | last post by:
I use GenericErrorPage.aspx for the redirect page when some error occur. I want to show some different according error statusCode . How can I get error statusCode form Server.GetLastError()?
4
by: Carmen de Lara | last post by:
hi all, i have a master detail form. In the datagrid control i have the following code Private Sub dtgCobD_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
5
by: OneFang | last post by:
Hi I hope I make sense here. I want to be able to obtain the name of the method that calls a method within my class. So If I have my class that has a method LogInfo() And my client code...
0
by: Yoel Mc Lennan | last post by:
Hello Group, I need to obtain recordset of an object COM made in VB6 and soon fill dataset, some idea of where is the error? Thanks. Imports System.Data Imports System.Configuration Public...
2
by: ME | last post by:
How would one obtain the parameter VALUES of a method that has already run? I can find the method using the StackTrace and StackFrame classes but once I find the method I would like to obtain the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.