Event Handling: Detecting The Control

ayozzhero

Well-known member
Joined
Apr 6, 2005
Messages
186
Location
Malaysia
Programming Experience
1-3
Dim editmode as boolean
Private Sub UpperPart_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles txtCBName.KeyPress, txtAccNo.KeyPress, _
txtNote.KeyPress, txtChequeNo.KeyPress, txtAddress.KeyPress
e.Handled = Not editmode
End Sub

That is a part of my code. How do I detect in which control (textbox) actually the key is pressed. e.g. I want to display (msgbox) the textbox content everytime a key is pressed in the textbox

Thank you
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
i hope this helps
VB.NET:
Dim Textbox as Textbox = CType(sender, Textbox)
'to do something specific with a certain textbox:
Select Case Textbox.Name
  Case "txtCBName"
	'Code
  Case "txtAccNo"
	'Code
  Case "txtNote"
	'Code
  Case "txtChequeNo"
	'Code
  Case "txtAddress"
	'Code
End Select
'simply display a messagebox
Messagebox.Show(Textbox.Text, Textbox.Name)
'Above Messagebox will show the contents of the textbox with the textbox's name in the title bar
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
glad to help, happy programming
 
Top Bottom