DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2008
    Posts
    61

    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,652
    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
    61
    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,652
    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
    61
    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
    61
    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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links