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.
KeyDown Event C# WinForm
Collapse
X
-
-
Originally posted by PlaterWhich control are you attaching the keydown event listeners?
protected override void OnKeyDown(KeyEv entArgs e)
{
if (e.KeyValue == Keys.Right)
this.Horizontal Scroll.Value = this.Horizontal Scroll.Minimum;
else if (e.KeyValue == Keys.Left)
this.Horizontal Scroll.Value = this.Horizontal Scroll.Maximum;
base.OnKeyDown( e);
}Comment
-
Originally posted by jmccomicI have UserControl that is DockStyle Fill on a Form. I am attaching the keydown events to the UserControl. Like this: ("this" is the UserControl)Comment
-
Originally posted by rjvrnjnHave you set the form's KeyPreview property to True? If not, the key events will not be trapped.Comment
-
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?Comment
-
Originally posted by PlaterIf 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.Comment
Comment