Results 1 to 11 of 11

Thread: [RESOLVED] Shortcut key to a form's button while a MdiForm is existed

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Location
    M'sia
    Posts
    53

    Resolved [RESOLVED] Shortcut key to a form's button while a MdiForm is existed

    Hi~ I am very fresh in VB, this forum really help me a lot.

    Actaully what I want to do is assign a shortcut key to a button (Alt+a) at form A. But, the problem is, system take priority of run MdiForm's menu first once i press "Alt" key on the keyboard.

    So, I think for another way to overcome this problem that is call the Command1_Click function by MdiForm's menu.

    The code I write is for the mdiForm menu is:
    vb Code:
    1. Private Sub menuAdd_Click()
    2.     Call formA.Command1_Click
    3. End Sub
    Sure, it doesn't run bcoz the data member .Command1_Click is not found.

    Anyone have an idea?
    Last edited by Ropyon; Apr 20th, 2007 at 05:47 AM.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Shortcut key to a form's button while a MdiForm is existed

    You can directly call like this
    vb Code:
    1. Private Sub menuAdd_Click()
    2.     btnAdd_Click
    3. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2007
    Location
    M'sia
    Posts
    53

    Re: Shortcut key to a form's button while a MdiForm is existed

    Thanks for your fast respond~

    It doesn't work. bcoz the btnAdd_Click function is in Form A, but menuAdd_Click function is in MidForm, is 2 different form~

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Shortcut key to a form's button while a MdiForm is existed

    You could do onething.Place a Function in a Module.And in the click event call that Function
    Last edited by danasegarane; Apr 20th, 2007 at 05:10 AM.
    Please mark you thread resolved using the Thread Tools as shown

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2007
    Location
    M'sia
    Posts
    53

    Re: Shortcut key to a form's button while a MdiForm is existed

    hmm~ i think of this way before, but is it suitable to create a new module just for a single form's local function?
    really appreciate your idea~ i will giv a try~ thX

    Anyway, now what i most want to know is How to assign a ShortCut to a form's button if a mdiForm is existed? It is the straightest way to solve my problem~

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Shortcut key to a form's button while a MdiForm is existed

    You can do this like this
    1.Trap the key press event
    2.In that Suppress that event.and call your click event
    Please mark you thread resolved using the Thread Tools as shown

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Shortcut key to a form's button while a MdiForm is existed

    Quote Originally Posted by Ropyon
    Hi~ I am very fresh in VB, this forum really help me a lot.

    Actaully what I want to do is assign a shortcut key to a button (Alt+a) at form A. But, the problem is, system take priority of run MdiForm's menu first once i press "Alt" key on the keyboard.
    Put this code in Form A
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
      If Shift = vbAltMask And KeyCode = vbKeyA Then
        'do what you want here
      End If
    
    End Sub
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Shortcut key to a form's button while a MdiForm is existed

    If you want to execute what is in the click event of a button on another from do
    Code:
    Form1.Command1.Value = True

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Shortcut key to a form's button while a MdiForm is existed

    Or just Form1.Command1_Click
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2007
    Location
    M'sia
    Posts
    53

    Re: Shortcut key to a form's button while a MdiForm is existed

    Quote Originally Posted by Hack
    If you want to execute what is in the click event of a button on another from do
    vb Code:
    1. Form1.Command1.Value = True
    LoL, what a simple code? But it was answered my question about execute another form's function from mdiForm!! thx Mod!!~

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2007
    Location
    M'sia
    Posts
    53

    Re: Shortcut key to a form's button while a MdiForm is existed

    Quote Originally Posted by Al42
    Put this code in Form A
    vb Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. If Shift = vbAltMask And KeyCode = vbKeyA Then
    3.     'do what you want here
    4. End If
    5. End Sub
    Yeah, this is actually what i want find out! Assign a ShortCut key to a Function.

    Once i press the "Alt + A" button, the function was executed! But I should replace the Form_KeyDown to Command1_KeyDown first.

    Thx alL of you efffort to help me~ appreciated and hope it wilL help other so.
    Last edited by Ropyon; Apr 21st, 2007 at 07:37 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
  •  



Click Here to Expand Forum to Full Width