Trapping arrow key strokes in an MDI form


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Trapping arrow key strokes in an MDI form

  1. #1
    Join Date
    Feb 2008
    Posts
    63

    Trapping arrow key strokes in an MDI form

    How can the arrow keys be trapped in an MDI form? Seems these are the only keys that are not usable. Something like this doesnít work as they would in a regular form.

    Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

    If e.KeyCode = Keys.Right Then
    '***Code ***
    End If

    If e.KeyData = Keys.Left Then
    '***Code ***
    End If

    End Sub

    Thanks for any help you can provide.

  2. #2
    Join Date
    Apr 2012
    Posts
    1
    I also have the same question and really, I would be very grateful for the quick answer, cuz now this inconvenience stops my work)) Thanks in advance!

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Instead of keycode try keyvalue
    Code:
    Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    		If e.KeyValue = Keys.Left Then
    		*****Whatever Herer*****
    		End If
    End Sub
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Feb 2008
    Posts
    63
    Gee Hack, you had me excited there for a moment. I noticed right off at the end of your SUB procedure you had “MyBase.KeyDown” where mine was “Me.KeyDown”. I thought this is the answer. As it turns out, it still doesn’t work. I had tried “Key.Value” before, but I was sure your “MyBase” was going to do it. Like Britney92, my project is at a stand still until something is found. Thanks for your help.

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    This works just fine for me
    Code:
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            Select Case e.KeyValue
                Case Keys.Left
                    MessageBox.Show("You hit the left arrow key")
                Case Keys.Right
                    MessageBox.Show("You hit the right arrow key")
                Case Keys.Up
                    MessageBox.Show("You hit the up arrow key")
                Case Keys.Down
                    MessageBox.Show("You hit the down arrow key")
            End Select
        End Sub
    You do have KeyPreview set to True, right?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  6. #6
    Join Date
    Feb 2008
    Posts
    63
    Thanks Hack for your help. I tried testing your last code and it worked fine in a form by itself, but when I tried it within the program Iím working on it doesnít work at all. When pressing the arrow keys it doesnít even go into the KeyDown procedure at all, but does when all other keys are pressed. Do you have any ideas what may be causing this? I really appreciate your help.

  7. #7
    Join Date
    Feb 2008
    Posts
    63
    Hack, as I said in my previous post, the code works fine, but not within my program. I did some more testing again and it seems that the code will work until a child form becomes present and then the arrow keys will stop functioning. Just thought I'd throw that into the mix.

Similar Threads

  1. Capturing the UP Arrow Key Part 2
    By liboc in forum C++
    Replies: 1
    Last Post: 04-24-2009, 12:12 AM
  2. Capturing the UP Arrow Key
    By liboc in forum C++
    Replies: 6
    Last Post: 04-23-2009, 05:41 AM
  3. Help: Shorcut key for a commandbutton
    By craver06 in forum VB Classic
    Replies: 10
    Last Post: 02-06-2008, 12:12 PM
  4. MDI Form
    By shers in forum .NET
    Replies: 1
    Last Post: 08-06-2007, 09:36 PM
  5. Hide MDI form while loading
    By brouse in forum VB Classic
    Replies: 2
    Last Post: 07-11-2007, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center