|
Bad solution. You do not need a Timer to do this. See my post to the OP for a better solution.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Handle your Form's KeyDown or KeyUp event (the KeyPreview property of the form needs to be turned on!) and look for the keycodes NumLock and Capital, then update whatever control you're using as a status indicator appropriately.
Private Sub Form_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.NumLock Then
' Keyboard.Numlock will return True or False depending on the status
' of the indicator light on the keyboard.
UpdateNumLockIndicator(My.Computer.Keyboard.NumLock)
End If
If e.KeyCode = Keys.Capital Then
UpdateCapsLockIndicator(My.Computer.Keyboard.CapsLock)
End If
End Sub
...and you do NOT need a Timer to do this!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Forgive but wouldn't this only handle the event when your form has focus? If you minimized your form and hit numlock, then maximized your form, it wouldn't know that the numlock was changed. I believe that's the purpose of the timer. So to solve this on a form_resize event, call the code on a windowstate change from minimized.
Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
if me.WindowState<>FormWindowState.Minimized then
UpdateNumLockIndicator(My.Computer.Keyboard.NumLock)
UpdateCapsLockIndicator(My.Computer.Keyboard.CapsLock)
end if
End Sub
Actually you would need to put it on the Form_Activate event as well...
|
|
|
|
|
There are a few other events you would have to handle to always know the state of the keyboard.
I'm not saying a timer is perfect, but definitely less coding.
Maybe a keyboard hook?
|
|
|
|
|
A keyboard hook would be the ultimate solution for the problem.
I personally, favor more coding over the use of more resources. Using a Timer and redrawing the status control every 100ms imports its own problems, especially in an environment that makes heavy use of custom drawn controls that take some time to draw.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
That's why I used a timer!
|
|
|
|
|
Yep, but the whole point is that a Timer is totally unnecessary and overkill since Ultra's example would needlessly redraw the status control every 100ms.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
thank for the answer but i am using visual basic.net 2003 in this vision i find error: (variable not declear) in "UpdateNumLockIndicator" & "My.Computer.Keyboard.NumLock"
please help me in this case.
thanks.
Rehan.
|
|
|
|
|
UpdateNumLockIndicator is a method that you have to supply to update whatever control your using to show the status of the toggle.
The My namespace is only available in VB.NET 2005. It doesn't exist in 2002 or 2003.
Public Declare Auto Function GetKeyState Lib "user32.dll" (ByVal KeyCode As Integer) As Short
Public ReadOnly Property NumLock As Boolean
Get
Return ((GetKeyState(144) And 1) > 0)
End Get
End Property
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
i am using below function but doen't work. if you please me how to use it this function in detail so i can solve my problem.
Public Declare Auto Function GetKeyState Lib "user32.dll" (ByVal KeyCode As Integer) As Short Public ReadOnly Property NumLock As Boolean
Get
Return ((GetKeyState(144) And 1) > 0)
End Get
End Property
Thanks
Rehan.
|
|
|
|
|
You update the status of the indicators by checking this NumLock Property in your KeyDown event code.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello,
i have a question about the WebBrowser.NewWindow Event.
How can i open an Popup in a new Window? In this event, i can only Cancel the Internet Explorer, but i cannot tell my application, that it should open the Page in a new Form?
In VisualBasic 6 it has worked, when i use the Microsoft WebBrowser COM Tool, then it works too, but i want to use the VisualBasic. net 2005 WebBrowser Class.
Has anybody a solution for this problem?
Thanks to you all
|
|
|
|
|
Does anyone know how to add a tasks window to a vb.net control? It's the small arrow at the top right area of the control. When a developer clicks on it, it shows a drop down menu.
|
|
|
|
|
how do i programatically insert a text at a particular cursor location in a text box
t.aransiola
|
|
|
|
|
replace the text "hello" with whatever you want
Select Case Me.TextBox1.SelectionStart
Case 0
Me.TextBox1.Text = "hello" & Me.TextBox1.Text
Case Else
Me.TextBox1.Text = Mid(Me.TextBox1.Text, 1, Me.TextBox1.SelectionStart) & _
"hello" & _
Mid(Me.TextBox1.Text, Me.TextBox1.SelectionStart + 1)
End Select
|
|
|
|
|
Hi,
What abt this solution
textbox1.SelectedText="Text To Insert"<br />
Hope this Works...
Nitin...
|
|
|
|
|
i stored text in a rich text control to a memo field in Access 2000 database.
I want to display teh content and append teh content using another richtext box control but the content of previous stored text shows garbage characters
any help
t.aransiola
|
|
|
|
|
Formatted text?? How is it formatted? How is the format information retained? Is it inline with the text, like HTML tags?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
not like HTML tags. Its like the text intermixed with some other ascii characters.
I will come with a sample characters it shows. i dont have it here now.
thank u
t.aransiola
|
|
|
|
|
please i need to know how to count the words in a sentence in console application using the mid function?
Thanks
|
|
|
|
|
Hi,
Why do you use mid by the way ?. Just split the sentence on space character and then finding the length of array gives you the number of words in the string.
Just simple as it looks.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Hi,
How do I run the excel macro from Visual Basic6.
thank you
|
|
|
|
|
you have to use MS Excel COM in VB.
your macro code will be running. in VB6.0 Editor.
Cheer
Pavan Pareta
|
|
|
|
|
Hi,
How i can get Hard Disk Serial No in VB Dot Net 2005 Application.
I want to get serial no in Text Box
Vikash Yadav
|
|
|
|
|