I need to override the Enter key for the entire form. In my Windows form,
when a user presses Enter, I want it to behave just like a Tab, except when
the focus is on a button. Here are the 2 methods I've tried:
public EstDefaults()
{
InitializeComponent();
KeyPress += new KeyPressEventHandler(EstDefaults_KeyPress);
}
private void EstDefaults_KeyPress(object sender, KeyPressEventArgs e)
{
if (!exit.Focused || !cancel.Focused || !Delete.Focused)
{
e.KeyChar = (char)9;
}
}
AND
public EstDefaults()
{
InitializeComponent();
KeyDown += new KeyEventHandler(EstDefaults_KeyDown);
}
private void EstDefaults_KeyDown(object sender, KeyEventArgs e)
{
if (!exit.Focused || !cancel.Focused || !Delete.Focused )
{
e.KeyCode = Keys.Tab;
}
}
The KeyPress does nothing, and the KeyDown won't compile because e.KeyCode
is read-only. KeyPreview is set to True at the form level.
What am I doing wrong? Thanks! 2 1686
Use keypress. If the key is "enter", set e.handled to "true". That
will make the control ignore the "enter" event. Then you can use the
GetNextControl().Focus or SelectNextControl methods (not sure which) to
handle activating the next control.
Irvin McCoy wrote:
I need to override the Enter key for the entire form. In my Windows form,
when a user presses Enter, I want it to behave just like a Tab, except when
the focus is on a button. Here are the 2 methods I've tried:
public EstDefaults()
{
InitializeComponent();
KeyPress += new KeyPressEventHandler(EstDefaults_KeyPress);
}
private void EstDefaults_KeyPress(object sender, KeyPressEventArgs e)
{
if (!exit.Focused || !cancel.Focused || !Delete.Focused)
{
e.KeyChar = (char)9;
}
}
AND
public EstDefaults()
{
InitializeComponent();
KeyDown += new KeyEventHandler(EstDefaults_KeyDown);
}
private void EstDefaults_KeyDown(object sender, KeyEventArgs e)
{
if (!exit.Focused || !cancel.Focused || !Delete.Focused )
{
e.KeyCode = Keys.Tab;
}
}
The KeyPress does nothing, and the KeyDown won't compile because e.KeyCode
is read-only. KeyPreview is set to True at the form level.
What am I doing wrong? Thanks!
Thanks, I'll try it.
If it ignores the Enter key, will it still go through the validation process?
"Martin Z" wrote:
Use keypress. If the key is "enter", set e.handled to "true". That
will make the control ignore the "enter" event. Then you can use the
GetNextControl().Focus or SelectNextControl methods (not sure which) to
handle activating the next control.
Irvin McCoy wrote:
I need to override the Enter key for the entire form. In my Windows form,
when a user presses Enter, I want it to behave just like a Tab, except when
the focus is on a button. Here are the 2 methods I've tried:
public EstDefaults()
{
InitializeComponent();
KeyPress += new KeyPressEventHandler(EstDefaults_KeyPress);
}
private void EstDefaults_KeyPress(object sender, KeyPressEventArgs e)
{
if (!exit.Focused || !cancel.Focused || !Delete.Focused)
{
e.KeyChar = (char)9;
}
}
AND
public EstDefaults()
{
InitializeComponent();
KeyDown += new KeyEventHandler(EstDefaults_KeyDown);
}
private void EstDefaults_KeyDown(object sender, KeyEventArgs e)
{
if (!exit.Focused || !cancel.Focused || !Delete.Focused )
{
e.KeyCode = Keys.Tab;
}
}
The KeyPress does nothing, and the KeyDown won't compile because e.KeyCode
is read-only. KeyPreview is set to True at the form level.
What am I doing wrong? Thanks!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andrew Durdin |
last post by:
In Python, you can override the behaviour of most operators for a
class, by defining __add__, __gt__, and the other special object
methods.
I noticed that, although there are special methods for...
|
by: Ali Eghtebas |
last post by:
Hi,
I have 3 questions regarding the code below:
1) Why can't I trap the KEYDOWN while I can trap KEYUP?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read...
|
by: Al Bahr |
last post by:
H
I need to combine Ink strokes with the background image into a bit map. Would appreciate any help
Thank
A
|
by: Amin Sobati |
last post by:
Hi,
I have two classes. Class2 inhertis Class1:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()
End Sub
End Class
Public Class Class2
|
by: Paulers |
last post by:
Hello,
I need to emulate keyboard strokes from a console application. The
console application monitors a textfile and when something is matched
in a text file I need the matched string outputted...
| |
by: sreenulanka |
last post by:
I have five panel each one layout is set to gridbag layout.and also i have one main panel, layout is box layout.all components add to container.my page is larger than screen.it is not moving with...
|
by: abcd |
last post by:
Is there a way to capture key strokes on a system using python (other
than pyHook)? can wxPython capture keystrokes for the system (not
just, say a text box)?
thanks
|
by: =?Utf-8?B?QWxleGFuZGVy?= |
last post by:
Hi! I am new to C#. I read two C# books in the last two days which only
covered the basics. And now I am on my third day. The books were really bad,
because they did not cover windows applications,...
|
by: r035198x |
last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize.
These were designed to be overridden according to specific general contracts. Other classes that...
|
by: shadyabhi |
last post by:
How can i accept key strokes like Ctrl+A etc etc ... i mean combination of 2 keys... Pls give a small peice of code to demonstrate...
i use gcc under linux platform
|
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,...
| |
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...
|
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,...
|
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...
|
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: 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...
|
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...
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |