Ok, my situation is like this.
I have a form with a few text boxes each with a 'validating' event, OK
& Cancel buttons, and have the AcceptButton/CancelButton/DialogResult
properties all set.
Situation 1: (works fine)
If the user enters invalid text in a text box, presses Enter in the
text box, the validation displays a msgbox. They now correct the text,
press Enter in the text box, it validates correctly this time and the
OK button click event fires.
Situation 2: (does not work)
If the user enters invalid text in a text box, clicks the OK button,
the validation displays a msgbox. They now correct the text, press
Enter in the text box, it validates correctly this time BUT the OK
button click event does not fire.
Why is situation 2 not working?
lostdreamz
-----------------------------
To recreate the situation 2 described above, create a new solution and
paste the code below over a blank form's 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 TextBox1 As System.Windows. Forms.TextBox
Friend WithEvents Button1 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.Button1 = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(32,
16)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Siz e = New System.Drawing. Size(104, 20)
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'Button1
'
Me.Button1.Dial ogResult =
System.Windows. Forms.DialogRes ult.OK
Me.Button1.Flat Style =
System.Windows. Forms.FlatStyle .System
Me.Button1.Loca tion = New System.Drawing. Point(48, 64)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 3
Me.Button1.Text = "ok"
'
'Form1
'
Me.AcceptButton = Me.Button1
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(168, 102)
Me.Controls.Add (Me.Button1)
Me.Controls.Add (Me.TextBox1)
Me.FormBorderSt yle =
System.Windows. Forms.FormBorde rStyle.FixedSin gle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPositio n =
System.Windows. Forms.FormStart Position.Center Screen
Me.Text = "Form1"
Me.ResumeLayout (False)
End Sub
#End Region
Private Sub TextBox1_Valida ting(ByVal sender As Object, ByVal
e As System.Componen tModel.CancelEv entArgs) Handles
TextBox1.Valida ting
If TextBox1.Text = "" Then
MsgBox("cannot be empty")
e.Cancel = True
End If
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal
e As System.EventArg s) Handles Button1.Click
End
End Sub
End Class 2 6022
Hi,
When you set e.cancel to true in the validating event it cancels the
ok buttons click event and sets the focus back to the textbox. http://msdn.microsoft.com/library/de...atingtopic.asp
Ken
-----------------
"lostdreamz " <yb***********@ ubgznvy.pbz> wrote in message
news:h9******** *************** *********@4ax.c om... Ok, my situation is like this.
I have a form with a few text boxes each with a 'validating' event, OK & Cancel buttons, and have the AcceptButton/CancelButton/DialogResult properties all set.
Situation 1: (works fine) If the user enters invalid text in a text box, presses Enter in the text box, the validation displays a msgbox. They now correct the text, press Enter in the text box, it validates correctly this time and the OK button click event fires.
Situation 2: (does not work) If the user enters invalid text in a text box, clicks the OK button, the validation displays a msgbox. They now correct the text, press Enter in the text box, it validates correctly this time BUT the OK button click event does not fire.
Why is situation 2 not working?
lostdreamz
Ken,
Thanks for responding. Perhaps you misread was I was saying in
Situation 2 yesterday.
The only way I can show you what I'm talking about is to tell you the
exact steps to recreate the problem.
1. Use the code for the form I sent you yesterday, or create a form
of your own with a text box and a button use the code below for the
validate event of the text box.
If TextBox1.Text = "" Then
MsgBox("cannot be empty")
e.Cancel = True
End If
2. Now, press the OK button when the textbox is clear and you will
get the message box. Click OK on the message box.
3. Now, type some text in the text box.
4. Now, this time instead of clicking the OK button to try to fire
it's Click event, I want you to press the Enter key while the focus is
still in the text box.
5. Notice, this time the validation was successful, but the Click
event was not fired from the Enter key being pressed in the textbox.
Note: If you do not click on the OK button, but always just press the
Enter key to fire the OK button Click event, the problem I described
above does not occur.
lostdreamz
On Tue, 13 Jan 2004 06:31:57 -0500, "Ken Tucker [MVP]"
<vb***@bellsout h.net> wrote: Hi,
When you set e.cancel to true in the validating event it cancels the ok buttons click event and sets the focus back to the textbox. http://msdn.microsoft.com/library/de...atingtopic.asp
Ken ----------------- Situation 2: (does not work) If the user enters invalid text in a text box, clicks the OK button, the validation displays a msgbox. They now correct the text, press Enter in the text box, it validates correctly this time BUT the OK button click event does not fire.
Why is situation 2 not working?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kevin Smith |
last post by:
I ran across a problem after installing the .NET framework Service
Pack 1 on both XP and Server 2003, so I thought I would post the
solution here in case anyone else ran across it.
After installing the service pack on my development machine, I started
getting an ObjectDisposedException every time I hit the enter button
while in a TextBox. The top of the call stack said the errant method
was System.Windows.Forms.Control.CreateHandle(),...
|
by: Jeff Haumesser |
last post by:
I have a form with the AcceptButton property set to a command button. I
also have a RichTextBox on the same form. With the AcceptButton property
set, I cannot enter a carriage return in the RichTextBox. It instead
activates the command button that is specified in the AcceptButton property.
Does anyone else have this problem and if so, how can I have both and
AcceptButton property set and able to enter a Carriage Return in the RTB...
|
by: Adam J. Schaff |
last post by:
I have noticed that if a user closes a form via pressing return (either
while the OK button has focus or if AcceptButton is set to OK for the form)
then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad
for me, because in my application, Form1 responds to an ENTER keypress by
calling Form2. If the user closes Form2 via an ENTER, then Form1 just
reopens it again, kind of trapping the user in Form2 (they can still close...
|
by: Jeff |
last post by:
Hello all.
I'm trying to figure out exactly what is going on here. I'm getting
different results on different forms, and it's driving me nuts.
For example, I have a form called FormFinish. It's AcceptButton is set
to btnExport and the CancelButton is set to btnCancel.
btnExport on FormFinish has no event code whatsoever (not even for
click.) When the user either clicks the button or presses enter on the
|
by: Alien2_51 |
last post by:
I have a form with it's AcceptButton property set to a button on my forms
click event, when I hit enter in runtime on the form, the cursor goes to an
hourglass for a second, as if it were doing something but does not hit the
breakpoint I have set, when I press the button the event procedure code
executes correctly and the break point is hit, what could be the problem...?
TIA
Dan
| |
by: Barney |
last post by:
Hi,
This is my first query in google groups. I expect to don´t do it
wrong, and excuse me for my english, i haven´t used it for years...
I´m making a user component that inherits from a textbox. I would like
to use the acceptbutton property of its parent form when the "enter"
key is pressed. Something like that.
private void txtAutocomp_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
|
by: Karsten Sosna |
last post by:
Hello NG,
i have a problem with the AcceptButton in VB.Net and C#. I have an empty
project with one form. On this form i take two buttons(Button1 and Button2).
Now i set the the AcceptButton-Property to Button2, compile the application
with the IDE. After the compilation the property is already set to Button2.
Now i add a new UserControl to the project and drop it on the
Form(AcceptButton = Button2). When i compile the project the property...
|
by: Al Biheiri |
last post by:
how do i create an AcceptButton in c#
user presses enter on textbox = button1.click
something like
AcceptButton = button1
|
by: Tony Johansson |
last post by:
Hello!
I'm reading a book which mentioned about this AcceptButton property for a
form which seems quite easy so I try to figure out how it works but I have
run into some small problems.
I have this small easy program below which show two buttons called button1
and button2.
In this program when the Enter key is clicked event handler for button1 is
called.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |