Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 2nd, 2005, 03:07 AM
hithere's Avatar
hithere hithere is offline
Learner
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: India
Posts: 450 hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 12 h 13 m 21 sec
Reputation Power: 18
keydown event of usercontrol not working

Hi friends,
I have one usercontrol in that i have keydown event.
But its not being getting called. The keypreview property is set to false. i tried changing it to true but then also its not working.
I want to change the backcolor of frame depending on key pressed
If user has pressed "F1" then change to blue
If user has pressed "F2" then change to red
If user has pressed "entrer" then call some function

Code:
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
If ques <= totalques Then
If KeyCode = vbKeyF1 Or KeyCode = vbKeyAdd Then
 Frame2.BackColor = RGB(0, 0, 255)
 Label1.Caption = "BUY"
ElseIf KeyCode = vbKeyF2 Or KeyCode = vbKeySubtract Then
 Frame2.BackColor = RGB(255, 0, 0)
 Label2.cpation = "SELL"
End If
If KeyCode = vbKeyReturn Or KeyCode = vbKeySeparator Then
 cnfrm = MsgBox("Confirm order", vbOKCancel)
 If cnfrm = vbOK Then
  test1
 Else
 End If
End If
End If
End Sub


Please tell me how to go abt it
Its very urgent
Thanx in advance

Reply With Quote
  #2  
Old August 2nd, 2005, 05:48 AM
sheeba's Avatar
sheeba sheeba is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jul 2005
Posts: 678 sheeba User rank is Corporal (100 - 500 Reputation Level)sheeba User rank is Corporal (100 - 500 Reputation Level)sheeba User rank is Corporal (100 - 500 Reputation Level)sheeba User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 8 m
Reputation Power: 5
Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 112 Then
Me.BackColor = RGB(0, 0, 255)

ElseIf KeyCode = 113 Then
Me.BackColor = RGB(255, 0, 0)

End If
End Sub

Reply With Quote
  #3  
Old August 3rd, 2005, 01:11 AM
hithere's Avatar
hithere hithere is offline
Learner
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: India
Posts: 450 hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 12 h 13 m 21 sec
Reputation Power: 18
Hi sheeba,
i changed the code to

Code:
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
MsgBox KeyCode
End Sub


when i press F1 it sometimes shows me msgbox two times with value of keycode as 112
and sometimes it displays help.
i want everytime the keyup event to be fired.
when i press F2 nothing happens
Please help me its very urgent.

Quote:
Originally Posted by sheeba
Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 112 Then
Me.BackColor = RGB(0, 0, 255)

ElseIf KeyCode = 113 Then
Me.BackColor = RGB(255, 0, 0)

End If
End Sub

Reply With Quote
  #4  
Old August 4th, 2005, 12:57 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
There is some form property setting that controls if the keyup event is passed to the form keyup handler or to whatever control the mouse pointer is over. But I don't recall what it's called, look at the available form properties or refer to the vb documentation.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #5  
Old August 4th, 2005, 10:00 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
Use a timer and the last code in the next link

http://vb-tec.de/inkey.htm

Reply With Quote
  #6  
Old August 13th, 2005, 03:13 AM
hithere's Avatar
hithere hithere is offline
Learner
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: India
Posts: 450 hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 12 h 13 m 21 sec
Reputation Power: 18
The proprty is KeyPreview and it should be set to true. Instead of using ActivexControl i used Simple VB project and now my code is working absolutely fine

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
While inkey$ <> ""
Wend
If ques <= totalques Then
If KeyCode = vbKeyF1 Or KeyCode = vbKeyAdd Then
 KeyCode = 0
 Frame2.BackColor = RGB(0, 0, 255)
 Label1.Caption = "BUY"
ElseIf KeyCode = vbKeyF2 Or KeyCode = vbKeySubtract Then
 KeyCode = 0
 Frame2.BackColor = RGB(255, 0, 0)
 Label1.Caption = "SELL"
End If
If KeyCode = vbKeyReturn Or KeyCode = vbKeySeparator Then
 KeyCode = 0
 cnfrm = MsgBox("Confirm order", vbOKCancel)
 If cnfrm = vbOK Then
  storedata "1"
  Text2.SetFocus
 End If
End If
End If
End Sub


Quote:
Originally Posted by Doug G
There is some form property setting that controls if the keyup event is passed to the form keyup handler or to whatever control the mouse pointer is over. But I don't recall what it's called, look at the available form properties or refer to the vb documentation.

Reply With Quote
  #7  
Old August 13th, 2005, 11:10 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
Thanks for posting the solution!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > keydown event of usercontrol not working


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT