Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard shortcut on a button

Status
Not open for further replies.

AKarim

Technical User
Mar 20, 2000
41
0
0
EU
Hi, <br>I have a graphical button, without any caption. I would like to assign a shortcut to it, but I only know to put &quot;&Compose&quot; in the caption property so that it works. The only thing is that if I do so the text appears in the button even if it is a graphical button. <br><br>Does someone know how can i put this shortcut ???
 
Ok - try this <br><br>you have a button called Command1, with no caption<br><br>so - create a menu option that calls the Command1_Click procedure, assign a shortcut to the menu option.<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Yes thanks Mike for the idea !!!<br>I tried it it works, as long as the menu is visible [As my window musnt have a menu the shortcut do not work]<br>Any other idea, or maybe is there a way of using the menu option invisible ?
 
hi,<br>&nbsp;&nbsp;trap the required key combination say &lt;ALT C&gt; in the form_keydown event and call the command1_click event from there.<br><br>hope this satisfies ur need.<br><br>thanx<br><br>suresh swaminathan<br>India.
 
Yes i thought about doing this after Mike gave his solution, but i'm using a MDIForm and events are only on mouse actions.<br><br>thnx to U<br>Karim
 
this doesn't work for making shortcuts ???<br><br>lets say u have command1 on a MDI form, the caption is <br>&quot;&Button&quot;<br><br>wouldn't Alt + B trigger the click event, or does that just give it the focus.. ?&nbsp;&nbsp;I dont know, but I would think it would trigger the click event<br><br>my 2 cents
 
Ok..... (haven't tried this)<br><br>Put the cmd bttn after a label in the tab order, assign a shortcut to the label (.Caption = &quot;Hi &There&quot; and so on) and then set forecolor the same as backcolor.<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
oh - and then call Command1_Click when the label get's focus.... <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
The problem is that there is no OnFocus event for a Label
 
Ok. Good, strong, technical point there..... Let me think.. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Right.<br><br>New standard project, add a button (with or without Caption - I don't mid) to the form<br>set the form1.KeyPreview to True and add the following code to the form.<br><FONT FACE=monospace><b><br>Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)<br>'<br>' If the user presses Alt-A, press the button<br>'<br>Dim ShiftTest<br>&nbsp;&nbsp;&nbsp;&nbsp;If KeyCode = 65 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShiftTest = Shift And 7<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If ShiftTest = 4 Then Command1_Click<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Sub<br><br>Private Sub Command1_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;gotcha!&quot;<br>End Sub<br></font></b> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Yes, Mike, this works really fine, but not in a MDIForm !<br>There's no KeyDown event in that type of form...<br><br>Karim
 
&lt;groan&gt;...... and I was doing so well... I'll look again <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top