From: Mr. X. on 2 Mar 2010 17:42 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 2 Mar 2010 17:55 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 2 Mar 2010 17:58 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 2 Mar 2010 20:31 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 4 Mar 2010 16:51 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/>
|
Next
|
Last
Pages: 1 2 Prev: Dynamically adding menu items and their OnClick events Next: User Controls Gets bigger |