By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,615 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,615 IT Pros & Developers. It's quick & easy.

How do i create shortcut keys for my buttons

P: 37
Hi,
I'm using Visual Basic 2005. I'm trying to create shortcut keys for my buttons. Currently, i have 2 buttons, presentButton and plotButton. When i press spacebar, it will perform the presentButton Click Event and when i press Enter, it will perform the plotButton Click Event. Is that possible?


Expand|Select|Wrap|Line Numbers
  1. Private Sub presentButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles presentButton.Click
  2.  
  3.     If count >= threshold Then
  4.        Me.responsePictureBox.Visible = True
  5.        tmrTimer.Enabled = True
  6.     End If
  7.  
  8. End Sub
  9.  
  10.  Private Sub plotButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plotButton.Click
  11.  
  12.         Audiogram.Show()
  13. End Sub
Sep 4 '07 #1
Share this Question
Share on Google+
9 Replies


sgrec7
P: 59
Hi,
I'm using Visual Basic 2005. I'm trying to create shortcut keys for my buttons. Currently, i have 2 buttons, presentButton and plotButton. When i press spacebar, it will perform the presentButton Click Event and when i press Enter, it will perform the plotButton Click Event. Is that possible?


Private Sub presentButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles presentButton.Click

If count >= threshold Then
Me.responsePictureBox.Visible = True
tmrTimer.Enabled = True
End If

End Sub

Private Sub plotButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plotButton.Click

Audiogram.Show()
End Sub
first of all you should read to your left and notice that all code must be written in code brackets

next thing, you said that you were using VB.net ??

this should work for the space/enter thing

Expand|Select|Wrap|Line Numbers
  1. Private Sub form1_Keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
  2. If e.KeyChar = Microsoft.VisualBasic.ChrW(32) then
    If count >= threshold Then
    Me.responsePictureBox.Visible = True
    tmrTimer.Enabled = True
    End If
    else If e.KeyChar = Microsoft.VisualBasic.ChrW(13) then
    Audiogram.Show(0
    end if
    end sub
  3.  
  4.  
that should do the same as what the buttons are doing, this is not a short cut for the button

to make a short cut for the button, in the properties for the button, find its text.

put a "&" before the letter that you want to be the short cut key.

to use the shortcut, while running the program, hold "Alt" and press the short cut key.

i hope thats sorted, remember the correct etiquette

sgrec7
Sep 5 '07 #2

Expert 5K+
P: 8,434
Seriously tigger, do not use Enter or space bar as your "shortcut" keys. You're just asking for trouble.

Space bar is used in Windows to trigger the current control, be that a button, checkbox or whatever. Enter is used to trigger the default button on the form.

If you want shortcut keys on them, use the old "& in the caption" technique. Assuming that still works after VB6, of course.
Sep 5 '07 #3

beacon
100+
P: 579
If I want to press a function key to reverse something that a user did, is there code for that?

For instance, a user clicks on a radio button to make it true. I want to set up F5 so that if the user didn't mean to select any radio button, F5 will return the value to false.

This is the closest thing in the forum to answering my question, but I'm not a seasoned vet at VB, so not everything in the code that was offered makes sense to me.
Nov 28 '07 #4

Expert 5K+
P: 8,434
As far as I know, you would have to make some record of each action taken by the user, so that you can reverse it.
Nov 28 '07 #5

beacon
100+
P: 579
As far as I know, you would have to make some record of each action taken by the user, so that you can reverse it.
Hi Killer,

Do you have any idea how to do what you suggested?? I'm not that advanced with VB and I appreciate your feedback, but I don't think your suggestion will help me write the code to accomplish what I need.

Thanks...
Nov 29 '07 #6

Expert 5K+
P: 8,434
Do you have any idea how to do what you suggested?? I'm not that advanced with VB and I appreciate your feedback, but I don't think your suggestion will help me write the code to accomplish what I need.
I'm afraid I won't have time to look into it in detail for at least a couple of weeks. Hopefully someone elsse here can help.

But in general, you could just add things onto an array, recording what was done (Like "ControlX = ABC" or whatever) and write some "Undo" code to read the last thing from the array and based on what's there, change one of the controls.
Nov 29 '07 #7

beacon
100+
P: 579
I'm afraid I won't have time to look into it in detail for at least a couple of weeks. Hopefully someone elsse here can help.

But in general, you could just add things onto an array, recording what was done (Like "ControlX = ABC" or whatever) and write some "Undo" code to read the last thing from the array and based on what's there, change one of the controls.
Hopefully someone else can help me with this. I understand what you're saying to do, but I don't have the experience in VB to accomplish it.
Dec 1 '07 #8

Expert 5K+
P: 8,434
Hopefully someone else can help me with this. I understand what you're saying to do, but I don't have the experience in VB to accomplish it.
I'm back from holidays. If I don't get back to you on this within a couple of days, feel free to post a reminder here.
Dec 9 '07 #9

Expert 5K+
P: 8,434
I'm back from holidays. If I don't get back to you on this within a couple of days, feel free to post a reminder here.
Oops! Another reminder to myself. I've been very busy.
Dec 12 '07 #10

Post your reply

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