Microsoft KB Archive/216175

= FIX: CTRL+C Does Not Copy From a Locked TextBox =

Article ID: 216175

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q216175



SYMPTOMS
If a textbox on a form has its Locked property set to True, and the CTRL+C shortcut is used to copy text in the textbox, the selected text will not be copied to the clipboard.



RESOLUTION
To work around this behavior, you must use the textbox's KeyDown event to check for a CTRL+C key combination. If CTRL+C does occur, then you must programatically put the selected text on the clipboard, as follows: If KeyCode = 67 And Shift = vbCtrlMask Then Clipboard.Clear Clipboard.SetText Text1.SelText End If See the MORE INFORMATION section below for an example of the workaround.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3.

For more information about Visual Studio 6.0 Service Packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed



Steps to Reproduce Behavior
 Create a new Visual Basic standard EXE project. Form1 is created by default. Add a textbox to the default form.  Add the following code to the default form's Form_Load event: Private Sub Form_Load Text1.Locked = True Text1.Text = "This is a test." End Sub

 Run the program. While the program is running, highlight the text in the textbox and hit CTRL+C. Then, try to paste test into Notepad or another editor. You will note that nothing is pasted or some text from an earlier copy and paste operation is pasted from the clipboard.  To work around the problem, add the following code to the textbox's KeyDown event: Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 67 And Shift = vbCtrlMask Then Clipboard.Clear Clipboard.SetText Text1.SelText End If End Sub  Run the program and try the copy-paste operation again. This time it will work properly.</li></ol>

NOTE: Using the shortcut menu available with the right-mouse button will work properly to copy text from a locked textbox.

<div class="references_section">