You can try using reflection below you can access the property "Text" from a 
control and extract the value.



            var type = sender.GetType();

            PropertyInfo pInfo = type.GetProperty("Text");

            string value = pInfo.GetValue(sender, null).ToString();

            MessageBox.Show(value);





David Loo

MCPD,MCP,MCTS

Analyst/Programmer



Description: Description: email_signature_logo



IT Vision Australia Pty Ltd (ABN: 34 309 336 904)
PO Box 881, Canning Bridge WA 6153
Level 3, Kirin Centre, 15 Ogilvie Road, Applecross, WA, 6153
P:  (08) 9315 7000    F:  (08) 9315 7088
E:  [email protected]    W: 
http://www.itvision.com.au<http://www.itvision.com.au/>
___________________________________________________________



NOTICE : This e-mail and any attachments are intended for the addressee(s) only 
and may
contain confidential or privileged material. Any unauthorised review, use, 
alteration,
disclosure or distribution of this e-mail (including any attachments) by an 
unintended recipient
is prohibited. If you are not the intended recipient please contact the sender 
as soon as
possible by return e-mail and then delete both messages.
___________________________________________________________



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



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





__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 7011 (20120329) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

<<inline: image001.jpg>>

Reply via email to