|
-
Jan 6th, 2005, 11:01 PM
#1
Thread Starter
Fanatic Member
Copy locked textbox
Is there an easy way to allow a user to copy text from a locked textbox? I need to display an ID number. The user may well want to copy the number to the clipborad though. I can add a keypress event to check for ctnl+c, but I'm not sure how to enable to Copy option in the right-click dropdown. Does anyone have code for this, or have a better control that would allow me to display text that can be copied but not changed?
-
Jan 6th, 2005, 11:07 PM
#2
-
Jan 6th, 2005, 11:09 PM
#3
Thread Starter
Fanatic Member
Re: Copy locked textbox
 Originally Posted by manavo11
But in a textbox, if you have the locked property set to true, the right-click-popup-menu does have the copy option  What did I misunderstand?
It does have the Copy option, but it is disabled. I want it enabled.
-
Jan 6th, 2005, 11:10 PM
#4
Frenzied Member
Re: Copy locked textbox
uhh
When i have a locked textbox you CAN still copy text from it
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
--------------------------------
"Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
"Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
-
Jan 6th, 2005, 11:12 PM
#5
Frenzied Member
Re: Copy locked textbox
It's not disabled. you can right-click Copy and then go to another window and ctrl + v ..ull paste the textboxes text
maybe u have the textbox enabled property set to false?
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
--------------------------------
"Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
"Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
-
Jan 6th, 2005, 11:28 PM
#6
Thread Starter
Fanatic Member
Re: Copy locked textbox
I get it now. (I've atually benn frustrated by this for years, because it "seems" to sometimes work and sometimes not).
The the whole text is selected, it can be copied. Simple as that. So I did this:
VB Code:
Private Sub txtText_KeyUp(KeyCode As Integer, Shift As Integer)
' Copy text for cntl+c.
If Shift = vbCtrlMask And KeyCode = 67 Then
Clipboard.Clear
Clipboard.SetText txtText.Text
End If
End Sub
Private Sub txtText_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
' Select text.
txtText.SelStart = 0
txtText.SelLength = Len(txtText.Text)
End Sub
Works like buttered green beans. Thanks!
-
Jan 6th, 2005, 11:33 PM
#7
Re: Copy locked textbox
I think you're just made it hard for yourself, WH - it's a normal windows functionality: before you can copy anything you'll have to select it first regardless. So, let the user decide what they want to do - if they need to copy some text then they are going to have to select it and then press ctrl+c or right click and ...
-
Jan 6th, 2005, 11:38 PM
#8
Thread Starter
Fanatic Member
Re: Copy locked textbox
But when the text is only partially selected, cntl+c doesn't copy. Acutally, cntl+c doesn't seem to copy at all when the text box is locked. So I HAVE to have a Key event to copy from a locked textbox. Right?
Last edited by WorkHorse; Jan 6th, 2005 at 11:43 PM.
-
Jan 6th, 2005, 11:50 PM
#9
Re: Copy locked textbox
No, wrong.
LOCKED doesn't disable COPY at all unless your textbox was subclassed somehow in your program so it affected this functionality. Selecting all text or just part of it will automatically activate that (COPY) menu item.
-
Jan 7th, 2005, 12:01 AM
#10
Thread Starter
Fanatic Member
Re: Copy locked textbox
 Originally Posted by RhinoBull
No, wrong.
LOCKED doesn't disable COPY at all unless your textbox was subclassed somehow in your program so it affected this functionality. Selecting all text or just part of it will automatically activate that (COPY) menu item.
Doesn't work for me. Try this. Start VB6 and make a new Standard EXE. Add a text box (it should be named Text1 and have Text property of Text1). Set Text1 Locked property to True.
Hit Start to run the app. Highlight the charcters "xt" in "Text1" of the textbox. Press Ctrl+C. Open notepad. Hit Ctrl+V (or Shift+Insert or use the menu to paste). Does it put "xt" in Notepad? I don't get "xt" when I do this. Notepad puts in whatever junk I had in the clipboard before before I started the app.
-
Jan 7th, 2005, 12:05 AM
#11
Re: Copy locked textbox
It works just like in any other windows based applications: copies selected text and paste it onto whatever ... Not sure why it isn't working for you ???
-
Jan 7th, 2005, 12:08 AM
#12
Thread Starter
Fanatic Member
Re: Copy locked textbox
 Originally Posted by RhinoBull
It works just like in any other windows based applications: copies selected text and paste it onto whatever ... Not sure why it isn't working for you ???
Serious? What you said about the drop down is true. The drop down copies any or all selected text. But Ctrl+C does not copy AT ALL for me when the texbox is locked (unless I code a Key event).
-
Jan 7th, 2005, 12:17 AM
#13
Re: Copy locked textbox
Hey Guys,
WH, it seems to not only disable the Ctl+C function, but the drop down menu is also limited (to Copy) aswell.
Edit: It sorta makes sense tho.
Bruce.
-
Jan 7th, 2005, 12:28 AM
#14
Re: Copy locked textbox
I got Ctl+C working and the dropdown has Copy + Paste enabled,
but of course the paste doesn't work since its locked.
Edit: Running SP6 could that be why?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2005, 12:29 AM
#15
Thread Starter
Fanatic Member
Re: Copy locked textbox
 Originally Posted by Bruce Fox
Hey Guys,
WH, it seems to not only disable the Ctl+C function, but the drop down menu is also limited (to Copy) aswell.
Edit: It sorta makes sense tho.
The only other options are Cut, Paste, Delete, and Undo--which wouldn't make sense for a locked box. Anyway, to cover the Ctrl+C problem and cover some of the problems my users have been having (which appears now to be attempting to copy when no text is selected) I've decided to use this:
VB Code:
Private Sub txtText_KeyUp(KeyCode As Integer, Shift As Integer)
' Check for Ctrl.
If Shift = vbCtrlMask Then
' Check KeyCode.
Select Case KeyCode
Case 65 ' Ctrl+A
' Select all text.
TextBoxSelectAll txtText
Case 67 ' Ctrl+C
' Copy selected text or copy all text
' if no text is selected.
If txtTextBox.SelLength = 0 Then
TextBoxCopyAll txtText
Else
TextBoxCopySelected txtText
End If
End Select
End If
End Sub
Private Sub txtText_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
' check for right button click.
If Button = 2 And txtText.SelLength = 0 Then
' Select all text.
TextBoxSelectAll txtText
End If
End Sub
Public Sub TextBoxSelectAll(ByVal txtTextBox As TextBox)
' Select all text.
txtTextBox.SelStart = 0
txtTextBox.SelLength = Len(txtText.Text)
End Sub
Public Sub TextBoxCopyAll(ByVal txtTextBox As TextBox)
' Copy all text to clipboard.
Clipboard.Clear
Clipboard.SetText txtTextBox.Text
End Sub
Public Sub TextBoxCopySelected(ByVal txtTextBox As TextBox)
' Copy selected text to clipboard.
Clipboard.Clear
Clipboard.SetText txtTextBox.SelText
End Sub
-
Jan 7th, 2005, 12:43 AM
#16
Thread Starter
Fanatic Member
Re: Copy locked textbox
Here is a trickier question. Why does the Sub TextBoxSelectAll work when the TextBox is passed ByVal? Shouldn't it only affect the the passed TextBox if it were passed ByRef?
-
Jan 7th, 2005, 04:55 AM
#17
Registered User
Re: Copy locked textbox
Hello
Don't worry i've got the exact problem. I think its because it might stop the c button when you press ctrl c so it only regesters the ctrl. I think.
-
Jan 7th, 2005, 09:15 AM
#18
Re: Copy locked textbox
 Originally Posted by WorkHorse
Here is a trickier question. Why does the Sub TextBoxSelectAll work when the TextBox is passed ByVal? Shouldn't it only affect the the passed TextBox if it were passed ByRef? 
Objects are always passed ByRef regardless.
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
|