Well, How do i bind a key in Vb6.0? and, i have searched.
How do i bind a key?
Collapse
X
-
hiOriginally posted by BlurbintLets say, W to?Code:form1.Backcolor = qbcolor (15)
tak e.g:
you may chose any key (see MSDN help on KeyDown)Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyF2 Then Form1.BackColor = QBColor(15) End Sub
Comment
-
It will work if you apply the code to the first control that receives the focus when you start your app. This will be the control with a tab index of 0Originally posted by BlurbintIt wont work.Comment
-
hiOriginally posted by willakawillIt will work if you apply the code to the first control that receives the focus when you start your app. This will be the control with a tab index of 0
of course should it be
Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
If KeyCode = vbKeyW Then Form1.BackColor = QBColor(15)
End Sub
how stupid to assign F2 to the color white ... :(Comment
-
I don't get it, would you explain it a little bit easier for me ,as i am new to vb.Originally posted by willakawillIt will work if you apply the code to the first control that receives the focus when you start your app. This will be the control with a tab index of 0
And Albert, it still doesnt work.Comment
-
In design view set the KeyPreview property of your form to trueOriginally posted by BlurbintI don't get it, would you explain it a little bit easier for me ,as i am new to vb.
And Albert, it still doesnt work.
Then Albert's code will workComment
-
sry, will explain ...Originally posted by willakawillIn design view set the KeyPreview property of your form to true
Then Albert's code will work
Create a form (usually the name will be Form1 if you don't change it)
then doubleclick in your newly made form --> a new (blank) screen will open with statement Sub Form_Load()
in righthand top corner you find a dropdown listbox -- select here:
KeyDown
Now a new sub will be opened called Form_KeyDown(.. ..
paste the previous code inhere
beware not to use sub Form_KeyDown and End Sub twice
now, when you start your project (F5) the program will rub, doing NOTHING untill you press the key W, then your form should turn paleComment
-
ah, now it works. But how do i add more bindings?Originally posted by albertwsry, will explain ...
Create a form (usually the name will be Form1 if you don't change it)
then doubleclick in your newly made form --> a new (blank) screen will open with statement Sub Form_Load()
in righthand top corner you find a dropdown listbox -- select here:
KeyDown
Now a new sub will be opened called Form_KeyDown(.. ..
paste the previous code inhere
beware not to use sub Form_KeyDown and End Sub twice
now, when you start your project (F5) the program will rub, doing NOTHING untill you press the key W, then your form should turn paleComment
-
Hi,Originally posted by Blurbintah, now it works. But how do i add more bindings?
To add more key bindings, you can do like this...
Regards,Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyW BackColor = QBColor(15) Case vbKeyF ForeColor = QBColor(5) Case vbKeyM MsgBox "Added more keys...", vbInformation End Select End Sub
M.Sivadhas.Comment
-
THanks, but just one more question, how do i deselect a thing? Like if i would wanna type in something, then press enter too remove it. But now it select the text box and nothing happens when you press enter, except the ding. so, now i want it too deselect the text box when i press enter. Hope you understand.Comment
-
hiOriginally posted by BlurbintTHanks, but just one more question, how do i deselect a thing? Like if i would wanna type in something, then press enter too remove it. But now it select the text box and nothing happens when you press enter, except the ding. so, now i want it too deselect the text box when i press enter. Hope you understand.
about the same procedure
select your object
doubleclick
then select in the right upper corner e.g: click / doubleclick or KEYDOWN
Code:Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) '--- clear text when hitting Enter If KeyCode = vbKeyReturn Then Text1.Text = vbNullString '--- clear text when hitting Backspace If KeyCode = vbKeyBack Then Text1.Text = vbNullString End Sub
Comment
Comment