From: Mr. X. on
Hello.
If I have the code : sender As System.Object
and sender is Button class.
How can I refer sender as a button ?

Thanks :)
From: Tom Shelton on
On 2010-03-02, Mr. X. <nospam(a)nospam_please.com> wrote:
> Hello.
> If I have the code : sender As System.Object
> and sender is Button class.
> How can I refer sender as a button ?
>
> Thanks :)

Dim b As Button = TryCast(sender, Button)

If b IsNot Nothing Then
' do cool stuff with the button specific stuff
Else
MessageBox.Show ("sender is not a button!")
End If

--
Tom Shelton
From: j1mb0jay on
Mr. X. wrote:
> Hello.
> If I have the code : sender As System.Object
> and sender is Button class.
> How can I refer sender as a button ?
>
> Thanks :)

What you are looking for is known as casting. You may want to look here.
http://www.codeproject.com/KB/dotnet/CheatSheetCastingNET.aspx

Hope this helps

--------------------------------
j1mb0jay
http://www.dotnethelp.co.uk
From: Herfried K. Wagner [MVP] on
Am 02.03.2010 23:42, schrieb Mr. X.:
> If I have the code : sender As System.Object
> and sender is Button class.
> How can I refer sender as a button ?

\\\
Dim SourceButton As Button = DirectCast(sender, Button)
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
From: Mr. X. on
Thanks.
What is the difference between tryCast and directCast ?

Thanks :)

"Herfried K. Wagner [MVP]" <hirf-spam-me-here(a)gmx.at> wrote in message
news:u24#9EnuKHA.5036(a)TK2MSFTNGP02.phx.gbl...
> Am 02.03.2010 23:42, schrieb Mr. X.:
>> If I have the code : sender As System.Object
>> and sender is Button class.
>> How can I refer sender as a button ?
>
> \\\
> Dim SourceButton As Button = DirectCast(sender, Button)
> ...
> ///
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>