473,395 Members | 1,761 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,395 software developers and data experts.

KeyDown Event C# WinForm

I am trying scroll horizontal scroll bars with the left and right arrow keys. I have tried registering the KeyDown and OnKeyDown events but with no success. Any help will be greatly appreciated.
Apr 2 '08 #1
6 10158
Plater
7,872 Expert 4TB
Which control are you attaching the keydown event listeners?
Apr 2 '08 #2
Which control are you attaching the keydown event listeners?
I have UserControl that is DockStyle Fill on a Form. I am attaching the keydown events to the UserControl. Like this: ("this" is the UserControl)

protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyValue == Keys.Right)
this.HorizontalScroll.Value = this.HorizontalScroll.Minimum;
else if (e.KeyValue == Keys.Left)
this.HorizontalScroll.Value = this.HorizontalScroll.Maximum;
base.OnKeyDown(e);
}
Apr 2 '08 #3
rjvrnjn
26
I have UserControl that is DockStyle Fill on a Form. I am attaching the keydown events to the UserControl. Like this: ("this" is the UserControl)
Have you set the form's KeyPreview property to True? If not, the key events will not be trapped.
Apr 2 '08 #4
Have you set the form's KeyPreview property to True? If not, the key events will not be trapped.
Sorry about that the UserControl is inside of a panel and the panel is on the form. I did set the form's KeyPreview property to true but did not seem to help.
Apr 2 '08 #5
Plater
7,872 Expert 4TB
If you user control has the focus it should work.
If the focus is on a textbox or some other control that would normally handle arrow keys, I think it will fail.
Also, isn't your logic backwards on that? You have the Right arrow key scroll left and the Left arrow key scrolling right.

Have you checked to see if that event is even getting fired? Maybe the key you are pressing shows up as a different key?
Apr 3 '08 #6
If you user control has the focus it should work.
If the focus is on a textbox or some other control that would normally handle arrow keys, I think it will fail.
Also, isn't your logic backwards on that? You have the Right arrow key scroll left and the Left arrow key scrolling right.

Have you checked to see if that event is even getting fired? Maybe the key you are pressing shows up as a different key?

Thanks, the logic was backwards and I was also having a focus issue. Thanks again for all of the help.
Apr 3 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mike M | last post by:
I am trying to detect the keydown of the arrow keys in a custom control that I am writing. As far as I can tell, pressing the arrow keys does not fire the KeyDown event at all. It behaves just...
3
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I...
3
by: trint | last post by:
Ok, I have tried to do this with the System.Web.UI and can't find anything for the webform. It seems much easier for a Winform. Any help in trapping Webform keydown event and keyup event is...
2
by: ZS | last post by:
Hi, On a form , I'm trying to trap when a shift key is pressed. Can someone explain how the KeyUp,KeyDown and Key Press event works for Forms. Thanks -ZS
0
by: Peter | last post by:
I have a VB6 program which can receive Keydown events on an ActiveX control. The ActiveX control can't fire keydown events so I put a picturebox below the ActiveX control. I write codes in...
2
by: Will Gillen | last post by:
I am building a hoem theatre app that is controlled by an IR Remote Control. The Remote has some keys that map to "keyboard" commands (i.e. PageUp, PageDown.). In this VB.NET application I have...
1
by: fripper | last post by:
I have a VB 2005 windows app and I want to recognize keydown events. I have a form key down event handler but it does not get control when a key is depressed. In playing around I found that if I...
6
by: mingchin.AT | last post by:
Hi, In Javascript, the simple way to check user input is to get the keycode. But for cross browser, its seems we need to have two different keycodes for the same key. There is a web page for...
5
by: ApexData | last post by:
This follows a previous post, when I was trying to capture a key pressed during the immediate opening of a form (ie in the first 3-secs before processing any of the code that followed it. It was...
3
by: win | last post by:
when the cursor is in a textbox, only coding in the keydown event of the textbox triggered, the coding in the keydown event of the form does not triggered! Problem: I need to change a VB6 program...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.