Join 136,545 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,837 people online right now. Registration is fast and FREE... Join Now!
I am creating a program in which a user is required to enter a password.... i was just wondering if there is a way for a toolstrip to become visible when the caps lock key is enabled (warning the user). I am still relatively new to vb.net so if you could please explain or provide code that would be greatly appreciated!
Thanks a lot in advance,
This post has been edited by yapper99: 22 Aug, 2008 - 08:38 PM
Yes you can, You need to put htis in the KeyDown() event
CODE
'If the user presses the Caps Lock If e.KeyCode = Keys.CapsLock Then 'ToolStrip Becomes Visible capsToolStrip.Visible = True Else 'ToolStrip Becomes InVisible capsToolStrip.Visible = False End If
This post has been edited by gbertoli3: 22 Aug, 2008 - 10:21 PM
Yes you can, You need to put htis in the KeyDown() event
CODE
'If the user presses the Caps Lock If e.KeyCode = Keys.CapsLock Then 'ToolStrip Becomes Visible capsToolStrip.Visible = True Else 'ToolStrip Becomes InVisible capsToolStrip.Visible = False End If
the warning will tell the user when they are entering a password in a webbrowser control so how would the keydown() event be??
Private Sub webBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Dim args As New KeyEventArgs(Keys.CapsLock) If args.KeyCode = Keys.CapsLock Then 'TODO CODE 'OR SHOW THE TOOLSTRIP MessageBox.Show("CapsLock is On") End If End Sub
It works for me
This post has been edited by gbertoli3: 23 Aug, 2008 - 09:13 AM
Private Sub webBrowser1_PreviewKeyDown(ByVal sender As Object, ByVal e As PreviewKeyDownEventArgs) If e.KeyCode = Keys.CapsLock Then 'TODO CODE End If End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.CapsLock Then DisplayCapsLockState End If End Sub
Private Sub DisplayCapsLockState() capsToolStrip.Visible = My.Computer.Keyboard.CapsLock If My.Computer.Keyboard.CapsLock Then Me.Label1.Text = "CAPSLOCK ON" Me.Label1.ForeColor = Color.Red Else Me.Label1.Text = "CapsLock OFF" Me.Label1.ForeColor = Color.Black End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DisplayCapsLockState() End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.CapsLock Then DisplayCapsLockState End If End Sub
Private Sub DisplayCapsLockState() capsToolStrip.Visible = My.Computer.Keyboard.CapsLock If My.Computer.Keyboard.CapsLock Then Me.Label1.Text = "CAPSLOCK ON" Me.Label1.ForeColor = Color.Red Else Me.Label1.Text = "CapsLock OFF" Me.Label1.ForeColor = Color.Black End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DisplayCapsLockState() End Sub
Adam what he wants is it to work from the WebBrowser() Control
This post has been edited by gbertoli3: 23 Aug, 2008 - 02:37 PM
Private Sub DisplayCapsLockState() capsToolStrip.Visible = My.Computer.Keyboard.CapsLock If My.Computer.Keyboard.CapsLock Then Me.Label1.Text = "CAPSLOCK ON" Me.Label1.ForeColor = Color.Red Else Me.Label1.Text = "CapsLock OFF" Me.Label1.ForeColor = Color.Black
End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DisplayCapsLockState() End Sub
Private Sub WebBrowser1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown If e.KeyCode = Keys.CapsLock Then DisplayCapsLockState() End If End Sub
Private Sub DisplayCapsLockState() capsToolStrip.Visible = My.Computer.Keyboard.CapsLock If My.Computer.Keyboard.CapsLock Then Me.Label1.Text = "CAPSLOCK ON" Me.Label1.ForeColor = Color.Red Else Me.Label1.Text = "CapsLock OFF" Me.Label1.ForeColor = Color.Black
End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DisplayCapsLockState() End Sub
Private Sub WebBrowser1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown If e.KeyCode = Keys.CapsLock Then DisplayCapsLockState() End If End Sub
Private Sub DisplayCapsLockState() capsToolStrip.Visible = My.Computer.Keyboard.CapsLock ' If My.Computer.Keyboard.CapsLock Then ' Me.Label1.Text = "CAPSLOCK ON" ' Me.Label1.ForeColor = Color.Red ' Else ' Me.Label1.Text = "CapsLock OFF" ' Me.Label1.ForeColor = Color.Black ' End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DisplayCapsLockState() End Sub
Private Sub WebBrowser1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown If e.KeyCode = Keys.CapsLock Then DisplayCapsLockState() End If End Sub
This post has been edited by AdamSpeight2008: 23 Aug, 2008 - 03:12 PM
Private Sub DisplayCapsLockState() capsToolStrip.Visible = My.Computer.Keyboard.CapsLock ' If My.Computer.Keyboard.CapsLock Then ' Me.Label1.Text = "CAPSLOCK ON" ' Me.Label1.ForeColor = Color.Red ' Else ' Me.Label1.Text = "CapsLock OFF" ' Me.Label1.ForeColor = Color.Black ' End If End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DisplayCapsLockState() End Sub
Private Sub WebBrowser1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown If e.KeyCode = Keys.CapsLock Then DisplayCapsLockState() End If End Sub
Sorry I was in a rush. I was not getting an error but It would only show Caps Lock is Off.