473,734 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Usercontrol : how to intercept "Enter" (originally asked in windowsforms.co ntrols group).

Sorry for the repost, but this group seems to be more "active" than the
group that I posted my question, and it's probably as valid here as there!

I have a usercontrol, which contains a textbox (as well as other controls).
The textbox is set for multiline, so it *should* accept an Enter Key to move
down to the next line.

However, I'm finding that if I put the control onto a form which has a
default Accept button set, then pressing enter when in the multi-line text
box will fire the click event on the default accept button, not create a new
line in the multi-line textbox.

I'm guessing I need to capture the enter key in the control before it gets
passed back up to the form and the default button gets processed.

How do I do this?

I'm writing in vb.net / framework 1.1.

Thanks in advance
Simon Verona
Oct 24 '07 #1
3 5516
On Oct 24, 7:32 am, "Simon Verona" <Nore...@nowher e.xxxwrote:
Sorry for the repost, but this group seems to be more "active" than the
group that I posted my question, and it's probably as valid here as there!

I have a usercontrol, which contains a textbox (as well as other controls).
The textbox is set for multiline, so it *should* accept an Enter Key to move
down to the next line.

However, I'm finding that if I put the control onto a form which has a
default Accept button set, then pressing enter when in the multi-line text
box will fire the click event on the default accept button, not create a new
line in the multi-line textbox.

I'm guessing I need to capture the enter key in the control before it gets
passed back up to the form and the default button gets processed.

How do I do this?

I'm writing in vb.net / framework 1.1.

Thanks in advance
Simon Verona
My train of thought would be to find out which event is fired first
the KeyDown event in the control/form even. Once you have that you
can see if your box has focus and act accordingly OR you can turn off
the accept / cancel button in the textbox.GotFocu s event and turn them
back on in the LostFocus event. This way the enter key would be used
in your textbox correctly and when the focus is lost everything
returns to normal.

Oct 24 '07 #2
Thanks for the idea, it worked a treat.

I ended up by picking up the gotfocus event on the text box in the
usercontrol, and checking the parentform.acce ptbutton, saving it's contents
in an object variable, and then making parentform.acce ptbutton=nothin g. I
then simply restore parentform.acce ptbutton to it's previous value in the
lostfocus event.

Regards
Simon

"cfps.Christian " <cf************ @gmail.comwrote in message
news:11******** **************@ t8g2000prg.goog legroups.com...
On Oct 24, 7:32 am, "Simon Verona" <Nore...@nowher e.xxxwrote:
>Sorry for the repost, but this group seems to be more "active" than the
group that I posted my question, and it's probably as valid here as
there!

I have a usercontrol, which contains a textbox (as well as other
controls).
The textbox is set for multiline, so it *should* accept an Enter Key to
move
down to the next line.

However, I'm finding that if I put the control onto a form which has a
default Accept button set, then pressing enter when in the multi-line
text
box will fire the click event on the default accept button, not create a
new
line in the multi-line textbox.

I'm guessing I need to capture the enter key in the control before it
gets
passed back up to the form and the default button gets processed.

How do I do this?

I'm writing in vb.net / framework 1.1.

Thanks in advance
Simon Verona

My train of thought would be to find out which event is fired first
the KeyDown event in the control/form even. Once you have that you
can see if your box has focus and act accordingly OR you can turn off
the accept / cancel button in the textbox.GotFocu s event and turn them
back on in the LostFocus event. This way the enter key would be used
in your textbox correctly and when the focus is lost everything
returns to normal.
Oct 25 '07 #3
"Simon Verona" <No*****@nowher e.xxxschrieb
Thanks for the idea, it worked a treat.

I ended up by picking up the gotfocus event on the text box in the
usercontrol, and checking the parentform.acce ptbutton, saving it's
contents in an object variable, and then making
parentform.acce ptbutton=nothin g. I then simply restore
parentform.acce ptbutton to it's previous value in the lostfocus
event.
Why not set the textbox' AcceptsReturn property to True?
Armin
Oct 25 '07 #4

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

Similar topics

2
1565
by: lemming | last post by:
I'd like to save the current record only with "enter" and noch with "shift-enter" (default). Has anyone an idea ? Thanks, Klaudia
3
2171
by: Luke Chung | last post by:
When I try to enter "" in a field or text box, it disappears. Is it possible to enter a pair of double quotes with no spaces between the quotes into a field? Luke
3
2792
by: Chuck Bowling | last post by:
I have a UserControl that contains a TextBox. I can't figure out how to capture and process the Enter key. I'm using the event code below... private void txt_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { if(e.KeyCode == Keys.Return) {
2
2016
by: marcia | last post by:
How can I capture (i.e., write an event handler) that runs after I press the "Enter" key? I'd like to prevent a Web Form from being submitted when the "Enter" key is pressed following the typing of some characters into a TextBox (ASP.NET) of a Web Form.
2
1421
by: MattB | last post by:
I have a WebForm that has a "reset" button and an "Enter" button. It's a long form, and users tend to hit the enter key at some point when they really want to tab to the next form field. How can I control this default behavior? I figured I could have an "are you sure?" confirmation if fields are blank, but I think I'd just rather make it so enter doesn't submit the form. Any examples or suggestions for me? Thanks! Matt
1
2944
by: Andrea Williams | last post by:
I've created a simple search form and a submit button. On click of the button, I have code-behind that runs and fills a datagrid. However, it the person is focused on one of the other controls and presses the "Enter" button, my submit button event code doesn't fire so my datagrid is either empty, or it shows a lot of blank rows. It looks like the submit happened, but since my code to fill the datagrid is in the submit_click method, it's...
2
2377
by: Hoss | last post by:
Hi guys, The framework of my page is an aspx page with a header and a footer. The header is a menu system and depending on what you select there different ascx pages are loaded into the middle part. So the entire page is encased in <form> tags. For this reason I cannot create <form> tags on a given ascx page. It screws things up. So, on one of my controls, I have the following -- set of 6 <input type=text id="myId">
0
1665
by: roxanaislam | last post by:
Hi: I have a search form in my application which has 4 dropdown list controls, one text box, one "GO" button, one "reset" button. When the "GO" button is clicked the form gets submitted and the results page is displayed. When I press the "enter" key nothing happens. I want to submit the form by pressing the "enter" key also. I have placed <input type="text" style="display:none"> after the <form> tag in the HTML section. Now if my cursor...
4
3879
by: roxanaislam | last post by:
Submitting Form by pressing the "ENTER" key -------------------------------------------------------------------------------- Hi: I have a search form in my application which has 4 dropdown list controls, one text box, one "GO" button, one "reset" button. When the "GO" button is clicked the form gets submitted and the results page is displayed. When I press the "enter" key nothing happens. I want to submit the form by pressing the "enter"...
0
8946
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, 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...
0
8776
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,...
1
9236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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
6735
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
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
2724
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.