Home All Groups Group Topic Archive Search About

understanding the sender object

Author
27 Jun 2005 6:19 PM
romy
Hello

dot.net winforms

How Do I make  casting from the sender object to controls in the form that
called the sub ?

Author
27 Jun 2005 6:07 PM
Herfried K. Wagner [MVP]
"romy" <romy1***@hotpop.com> schrieb:
> How Do I make  casting from the sender object to controls in the form that
> called the sub ?

If you use a common handler for controls of different type:

\\\
Select Case True
    Case TypeOf sender Is Button
        Dim SourceControl As Button = DirectCast(sender, Button)
        ...
    Case TypeOf sender Is ListBox
        Dim SourceControl As ListBox = DirectCast(sender, ListBox)
    ...
End Select
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Jun 2005 6:14 PM
Cor Ligthert
Romy,

A sender can be any object. In the case of the control you know it mostly
therefore you can than set forever if it is by instance a button
\\\
directcast(sender,button1).Performclick
///
However if you need by instance the text from a control than this is as well
enough
\\\
directcast(sender,control).Text
///
Text is in every control.

I hope this helps,

Cor