473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

acceptbutton

Hello, I'm working on a set of forms inherited from the windows form. Within
these forms I often use keyevents to perform certain functions i.e.
'return/enter in a textbox' to submit a value to a routine, perform a search
or just to send a tab.

As I have no one button on the form that I would always want to fire a click
when I hit enter I have the acceptbutton set to nothing. This causes the
obvious problem of the windows default beep sounding everytime the key is
pressed.

I have attempted to change the inherited form, setting a default button to
be the accept button, this stopped the beep but also stopped the keyevent
from firing too.

I also set up a click event for this default button to send a processcmdkey
or processkeydialog call so that the keyevent would fire as part of the click
event, no luck though.

I have tried to override processcmdkey and processkeydialog both to no
avail, I cannot seem to capture the event the acceptbutton event hits.

My target is to stop the beep AND still process the keyevent, thank you in
advance for any help.
Nov 21 '05 #1
3 2476
Hi,

You can set "e.handled = True" in the event keyPress and this way you'll
silence the beep.

As a proof of concept:

One button and one TextBox:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar.Equals(ControlChars.Cr) Then
Me.Button1_Click(Nothing, Nothing)
e.Handled = True
End If
End Sub

Best wishes,

Juan Pedro González
Nov 21 '05 #2
"js1300" <js****@discussions.microsoft.com> schrieb
Hello, I'm working on a set of forms inherited from the windows
form. Within these forms I often use keyevents to perform certain
functions i.e. 'return/enter in a textbox' to submit a value to a
routine, perform a search or just to send a tab.

As I have no one button on the form that I would always want to fire
a click when I hit enter I have the acceptbutton set to nothing.
This causes the obvious problem of the windows default beep sounding
everytime the key is pressed.

I have attempted to change the inherited form, setting a default
button to be the accept button, this stopped the beep but also
stopped the keyevent from firing too.

I also set up a click event for this default button to send a
processcmdkey or processkeydialog call so that the keyevent would
fire as part of the click event, no luck though.

I have tried to override processcmdkey and processkeydialog both to
no avail, I cannot seem to capture the event the acceptbutton event
hits.

My target is to stop the beep AND still process the keyevent, thank
you in advance for any help.

In the textbox' keypress event, set e.handled = true. It beeps because CR is
not handled.

Private Sub TextBox1_KeyPress( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress

If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
End Sub

Note, it doesn't beep because it's the *key* that isn't handled. It beeps
because the *char* (CR) is not handled (therefore keypress, not keydown).
Means, same happens if you press Ctrl+A to enter chr(1) into the textbox.
You would have to handle this too.
Armin

Nov 21 '05 #3
Excellent stuff, I have integrated that into my inherited textboxes and I now
have the action I want. Thank you both.
Nov 21 '05 #4

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

Similar topics

0
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...
0
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...
2
by: lostdreamz | last post by:
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. ...
15
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...
1
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....
2
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....
0
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...
2
by: sonicm | last post by:
Hi, I have a search for where we want the user to enter the search criteria in at the top and press enter, then the results are shown in a datagrid which we set the focus to. Once they select...
1
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
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.