473,888 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textbox Events

I have a simple form with one button and one text box. In the Form, I create
an array list to track the events by adding a descriptive string item to the
arraylist in each event. I first Click on the Button then Click on the
TextBox and enter an "a" then click on the Button again. The following is
what I get for the event tracking Arraylist:

but - GotFocus
but - Clicked
but - LostFocus
txt - Changed
but - GotFocus
but - Clicked

No where do I get the events Textbox.GotFocu s or TextBox.LostFoc us or
TextBox.Validat ing or TextBox.Validat ed firing. Note that the
TextBox.CauseVa lidation is set to True at Design time.

--
Dennis in Houston
Nov 21 '05 #1
10 3139
Hi,

The validating event is fired when the control you are moving to has
it causes validation property set to true. I have in the past deleted a
control and readded it. I found the code in the existing event handlers for
the old control did not work. I had to add a new event handler and copy the
code from the old event handler. Maybe this will help.

Ken
---------------
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
I have a simple form with one button and one text box. In the Form, I
create
an array list to track the events by adding a descriptive string item to the
arraylist in each event. I first Click on the Button then Click on the
TextBox and enter an "a" then click on the Button again. The following is
what I get for the event tracking Arraylist:

but - GotFocus
but - Clicked
but - LostFocus
txt - Changed
but - GotFocus
but - Clicked

No where do I get the events Textbox.GotFocu s or TextBox.LostFoc us or
TextBox.Validat ing or TextBox.Validat ed firing. Note that the
TextBox.CauseVa lidation is set to True at Design time.

--
Dennis in Houston
Nov 21 '05 #2
Ken,

Txt.changed is fired is in Dennis text. However your answer could have been
true.

Cor
Nov 21 '05 #3
Dennis,

I tried this,
I put a textbox and a button on a form
I pasted in this code
Than I run the code, and typed in "Dennis" in the textbox. Than it showed
"Hello Dennis".
How do you catch those events, probably is there the problem.

\\\
Private Sub TextBox1_Valida ting(ByVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) _
Handles TextBox1.Valida ting
MessageBox.Show ("Hello " & TextBox1.Text)
End Sub
///

I hope this helps?

Cor
Nov 21 '05 #4
Cor, in each event, I add an item to my tracking arraylist like so:

Private Sub TextBox1_Valida ting(ByVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) _
Handles TextBox1.Valida ting
TrackingArray.A dd("txt - Validating")
End Sub

I then have an event on the form that when it is clicked, the program breaks
and I print out the TrackingArray. This gives me a history of what was fired
in what sequence. Note that I also tried adding a message box like you did
and got nothing. Did you check if the gotfocus and lost focus events are
firing? Mine don't. Any idea what the problem is? It's a simple form and
it's really annoying that it doesn't work and follow M'soft's documentation
on what should fire. I know the text box changed event fires but why not the
others?

"Cor Ligthert" wrote:
Dennis,

I tried this,
I put a textbox and a button on a form
I pasted in this code
Than I run the code, and typed in "Dennis" in the textbox. Than it showed
"Hello Dennis".
How do you catch those events, probably is there the problem.

\\\
Private Sub TextBox1_Valida ting(ByVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) _
Handles TextBox1.Valida ting
MessageBox.Show ("Hello " & TextBox1.Text)
End Sub
///

I hope this helps?

Cor

Nov 21 '05 #5
Here's my code and it's in a separate project with only the form with one
button and one text box...very simple.

dim ev as arraylist = new arraylist

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
ev.Add("but - Click")
End Sub

Private Sub TextBox1_GotFoc us(ByVal sender As System.Object, ByVal e As
System.EventArg s)
ev.Add("text - gotfocus")
End Sub

Private Sub TextBox1_Valida ting(ByVal sender As System.Object, ByVal e As
System.Componen tModel.CancelEv entArgs)
ev.Add("text - Validating")
MsgBox("Trackin g", MsgBoxStyle.OKO nly, "I'm in Validating")
End Sub

Private Sub TextBox1_LostFo cus(ByVal sender As System.Object, ByVal e As
System.EventArg s)
ev.Add("Text - LostFocus")
End Sub

Private Sub Button_GotFocus (ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.GotFocu s
ev.Add("but - GotFocus")
End Sub

Private Sub Button_LostFocu s(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.LostFoc us
ev.Add("but - LostFocus")
End Sub

Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles TextBox1.TextCh anged
ev.Add("text - Changed")
End Sub

Private Sub Form1_Click(ByV al sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Click
Dim i As Integer = 0 'Have a Break set on this line then view ev in
the command editor.
End Sub
End Class

"Cor Ligthert" wrote:
Dennis,

I tried this,
I put a textbox and a button on a form
I pasted in this code
Than I run the code, and typed in "Dennis" in the textbox. Than it showed
"Hello Dennis".
How do you catch those events, probably is there the problem.

\\\
Private Sub TextBox1_Valida ting(ByVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) _
Handles TextBox1.Valida ting
MessageBox.Show ("Hello " & TextBox1.Text)
End Sub
///

I hope this helps?

Cor

Nov 21 '05 #6
Dennis,

Do you see that in this code is your code is almost what Ken wrote.

However the strange thing is that you have a handler with the
textbox.textbox changed, and that was in your result text.

So probably you deleted the textbox once. Added it again and did than add
afterwards as well the handler for the textchanged.

Are you trying to confuse us

:-)

no problem I hope this helps

Cor
Nov 21 '05 #7
Ken,

See my last message to Dennis.

Your answer was right,

However it was probably a little bit confusing what Dennis did.

Cor
Nov 21 '05 #8
I am not trying to confuse anyone. I did not delete the text box at any
time. For the sake of argument, I tried it again exactly as I did it the
first time. I started a new project then added a button1 and text box and the
public variable "eventtrack er as an arraylist. This time it seemed to track
all the events ok. However, the textbox1.LostFo cus event fired before the
textbox1.Valida ting event which is contrary to the M'soft's documentation
which says the validating event fires before the lostfocus event. This
eratic behavior of the control events makes if difficult and seems to be
inexcusable on Microsoft's part. Here is the complete project code:

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub _
InitializeCompo nent ()
Me.Button1 = New System.Windows. Forms.Button
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(184, 146)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing. Size(76, 24)
Me.Button1.TabI ndex = 0
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(184, 62)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Siz e = New System.Drawing. Size(84, 20)
Me.TextBox1.Tab Index = 1
Me.TextBox1.Tex t = ""
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 262)
Me.Controls.Add (Me.TextBox1)
Me.Controls.Add (Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Public eventtracker As ArrayList = New ArrayList

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As _
System.EventArg s) Handles MyBase.Load

End Sub

Private Sub TextBox1_GotFoc us(ByVal sender As Object, ByVal e As _
System.EventArg s) Handles TextBox1.GotFoc us
eventtracker.Ad d("textbox1 - gotfocus")
End Sub

Private Sub TextBox1_TextCh anged(ByVal sender As Object, ByVal e As _
System.EventArg s) Handles TextBox1.TextCh anged
eventtracker.Ad d("textbox1 - TextChanged")
End Sub

Private Sub TextBox1_Leave( ByVal sender As Object, ByVal e As _
System.EventArg s) Handles TextBox1.Leave
eventtracker.Ad d("textbox1 - Leave")
End Sub

Private Sub TextBox1_LostFo cus(ByVal sender As Object, ByVal e As _
System.EventArg s) Handles TextBox1.LostFo cus
eventtracker.Ad d("textbox1 - Lostfocus")
End Sub
Private Sub TextBox1_Valida ting(ByVal sender As Object, ByVal e As _
System.Componen tModel.CancelEv entArgs) Handles TextBox1.Valida ting
eventtracker.Ad d("textbox1 - Validating")
End Sub

Private Sub Button1_Click(B yVal sender As Object, ByVal e As _
System.EventArg s) Handles Button1.Click
eventtracker.Ad d("button1 - Click")
End Sub
Private Sub Button1_GotFocu s(ByVal sender As Object, ByVal e As _
System.EventArg s) Handles Button1.GotFocu s
eventtracker.Ad d("button1 - gotfocus")
End Sub

Private Sub Button1_LostFoc us(ByVal sender As Object, ByVal e As _
System.EventArg s) Handles Button1.LostFoc us
eventtracker.Ad d("button1 - lostfocus")
End Sub

Private Sub Form1_Click(ByV al sender As Object, ByVal e As _
System.EventArg s) Handles MyBase.Click
Dim s As String
Dim i As Integer
While i < eventtracker.Co unt
s = s & eventtracker(i) .ToString & vbLf
i = i + 1
End While
MsgBox(s, MsgBoxStyle.OKO nly, "Event Track...")

End Sub
End Class

"Cor Ligthert" wrote:
Dennis,

Do you see that in this code is your code is almost what Ken wrote.

However the strange thing is that you have a handler with the
textbox.textbox changed, and that was in your result text.

So probably you deleted the textbox once. Added it again and did than add
afterwards as well the handler for the textchanged.

Are you trying to confuse us

:-)

no problem I hope this helps

Cor

Nov 21 '05 #9
I see what happened now. The handles xxxx.xx somehow got removed from the
sub statement. I did not delete the text box and have no idea how they got
removed. Still, the TextBox lostfocus event fires before the Validating
event.

"Cor Ligthert" wrote:
Dennis,

Do you see that in this code is your code is almost what Ken wrote.

However the strange thing is that you have a handler with the
textbox.textbox changed, and that was in your result text.

So probably you deleted the textbox once. Added it again and did than add
afterwards as well the handler for the textchanged.

Are you trying to confuse us

:-)

no problem I hope this helps

Cor

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2140
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox should be set to a, selectable, in-focus color. 2) Out-of-focus color, when the textbox loses focus the backcolor property of the textbox should be set to a, selectable, out-of-focus color.
7
5817
by: Seash | last post by:
Hi friends , here is the sample code private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar == 13) //enter { txtbox2.Focus(); }
28
4384
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I added a class to project and it's named XmlApi(). In the XmlAPI() class I have simple code as following XmlAPI() { string str = "Some Text";
11
4589
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing opinion of how I want to handle the 'user experience' in the application I'm creating. While I know I could allow the user to enter in number and alpha text - in a text box - and then tell them when the execuate a command "This is not numeric data", I...
8
30424
by: John | last post by:
Hi, I am developing an application using VB.Net and hope that the textbox can process features which are similar to auto-complete features in Window. For example, when user types "ap" in a textbox and the data associated to the textbox contains ("apple", "applet", "application"......), the application will suggest "apple" to the user to select and user can either select the suggestion or continue to type another word he disires. How...
2
8049
by: Jonathan Allen | last post by:
In dialog boxes in Windows, the text in TextBox is automatically selected if you tab into the TextBox , but not when you select the TextBox using the mouse. What is the preferred way to support this in VB/C# 2005? -- Jonathan Allen
8
5098
by: Filipe Marcelino | last post by:
Hi, I'm trying to create a textbox inheriting from the standard textbox. I would like to: 1. repaint the textbox border; 2. define a color for that border; Till now I made this:
5
7462
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if the user does indeed move the cursor to another textbox, but if the user clicks my "done" toolstripbutton after making a change in the textbox but without moving the cursor out, the validated event never fires. I have a pretty bad workaround where...
1
6348
by: JFKJr | last post by:
Hello everyone, the following Access VBA code opens an excel file and creates textboxes in a given range of cells dynamically. The code attaches "MouseUP" and "Exit" events to the textboxes (using the following "DateTextBox" class module). Whenever a user enters in to the textbox, the code displays "Please enter date in mm/dd/yyyy format (for ex: 01/01/2009)." message which is accomplished using "MouseUp" event. And, I used "Exit" event to...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5817
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4244
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.