Click to See Complete Forum and Search --> : [RESOLVED] disabling text box


stin
February 23rd, 2010, 02:32 PM
I have a text box that I want to mostly disable. I would like the user to be able to copy the text, but that's all.
Here's the code for the keyDown event:

e.Handled = True
If e.KeyCode = Keys.ControlKey + Keys.C Then
System.Windows.Forms.Clipboard.SetText(rtbErrorList.Text)
End If


I'm never getting into the If when I press ^C. Any suggestions?

DataMiser
February 23rd, 2010, 04:20 PM
Try e.KeyData instead of E.KeyCode

ComITSolutions
February 23rd, 2010, 10:13 PM
If Only copying the text in the text box no other operation is required you can set ReadOnly property to True, Still you can copy the text.

I think you are looking for code something like below:

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If My.Computer.Keyboard.CtrlKeyDown Then
Select Case e.KeyCode
Case Keys.C
Case Keys.V
Case Keys.Right
Case Keys.Left
Case Else
e.Handled = True
End Select
Else
Select Case e.KeyCode
Case Keys.Right
Case Keys.Left
Case Else
e.Handled = True
End Select

End If
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
e.Handled = True
End Sub

DataMiser
February 24th, 2010, 12:16 AM
The keydata should work also. I tested it under VS2005 and KeyData was = Keys.Control + Keys.C when Control + C was pressed

ComITSolutions
February 24th, 2010, 12:30 AM
The keydata should work also. I tested it under VS2005 and KeyData was = Keys.Control + Keys.C when Control + C was pressed

Yes, I agree. many people wouldn't have explored My.Computer, I just wanted freshers, newcomers and others to know about it.

stin
February 24th, 2010, 07:34 AM
Wow, I can't believe I missed that (well can't is such a strong word :)). Read-only is exactly what I was looking for. Thank you folks also for the heads up about the keyData.