How to return just the Text value from "sender"

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

I see that MsgBox(sender.ToString()) will return a string that includes the
Text value of a button...

Is there a way to return only the Text value (i.e., some additional property
designate) ?
 
I see that MsgBox(sender.ToString()) will return a string that includes the
Text value of a button...

Is there a way to return only the Text value (i.e., some additional property
designate) ?

If you know that it is a button, you can use this line:

DirectCast(sender, Button).Text

Chris
 
Rob,

By convention, sender usually represents the object that has raised an event.

If you know the type of the object you can convert it to its actual type and
then reference any of the object's properties, etc.

For example, if you know that sender is a button:

Dim btn As Button = CType (sender, Button)

Now you have access to the button's properties and methods in the btn
reference.

Kerry Moorman
 
Yes. In order to get the Text property from the sender object, you need to
cast it to a button:

MsgBox(CType(sender, Button).Text)
 
If you know that it is a button, you can use this line:

DirectCast(sender, Button).Text

Chris

If you know that it is a button, you can use this line:

Or really you could cast sender into a Control to cover a wider range
of controls

DirectCast(sender, Control).Text

Thanks,

Seth Rowe
 
Back
Top