If you were expecting various types to hit that event then you'd just need to 
check the type before casting it...

        If TypeOf sender Is Button Then
            MessageBox.Show(CType(sender, Button).Text)
        ElseIf TypeOf sender Is TextBox Then
            MessageBox.Show(CType(sender, TextBox).Text)
        End If

Regards,

Nathan Keir
Systems Analyst
John Deere Financial Limited A.C.N. 078 714 646
Australian Credit Licence Number 391484
Incorporated in Queensland, Australia
166-170 Magnesium Drive, Crestmead, QLD, Australia 4132
PO Box 1544, Browns Plains BC, QLD, Australia 4118
+61 7 3802 3274 (office)
+61 7 3802 3142 (fax)
[email protected]<mailto:[email protected]>
www.JohnDeere.com.au<http://www.johndeere.com.au/>
CONFIDENTIALITY. This message, including attachments, may be confidential. If 
you believe this message was sent to you in error, do not read it. If you are 
not the intended recipient, any retention, dissemination, distribution, or 
copying of this communication is strictly prohibited. Please reply to the 
sender that you have received the message in error and delete it.

From: [email protected] [mailto:[email protected]] On 
Behalf Of Ian Thomas
Sent: Friday, 30 March 2012 4:16 PM
To: 'ozDotNet'
Subject: RE: WinForms - button text from sender object

Yes, that works -
CType(sender, Button).Text) in VB.NET - for a Button.
- but I thought there was something more general, though the .Text property 
isn't going to be uniform across controls.
I'll go for that solution. thx
________________________________

Ian Thomas
Victoria Park, Western Australia

________________________________
From: [email protected] [mailto:[email protected]] On 
Behalf Of Wallace Turner
Sent: Friday, March 30, 2012 2:03 PM
To: ozDotNet
Subject: Re: WinForms - button text from sender object

C#

((TextBox)sender).Text ?

On 30/03/2012 2:01 PM, Ian Thomas wrote:
Hello folks
I've forgotten how to get the text from a button click that handles multiple 
buttons -
Private Sub Buttons_Click(ByVal sender As Object, ByVal e As EventArgs) _
        Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click
(VB.NET above)
sender.ToString gives me the whole object description with its .Text property, 
but what's the simple expression to get just that text?

System.Windows.Forms.Button, Text: MyButtonText


________________________________

Ian Thomas
Victoria Park, Western Australia

Reply via email to