|
-
February 23rd, 2010, 03:32 PM
#1
[RESOLVED] disabling text box
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:
Code:
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?
-
February 23rd, 2010, 05:20 PM
#2
Re: disabling text box
Try e.KeyData instead of E.KeyCode
-
February 23rd, 2010, 11:13 PM
#3
Re: disabling text box
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:
Code:
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
Last edited by ComITSolutions; February 24th, 2010 at 06:34 AM.
Encourage the efforts of fellow members by rating
Lets not Spoon Feed and create pool of lazy programmers
- ComIT Solutions
-
February 24th, 2010, 01:16 AM
#4
Re: disabling text box
The keydata should work also. I tested it under VS2005 and KeyData was = Keys.Control + Keys.C when Control + C was pressed
-
February 24th, 2010, 01:30 AM
#5
Re: disabling text box
 Originally Posted by DataMiser
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.
Encourage the efforts of fellow members by rating
Lets not Spoon Feed and create pool of lazy programmers
- ComIT Solutions
-
February 24th, 2010, 08:34 AM
#6
Re: disabling text box
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|