Re: Textbox context menu on a label control

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Since VB labels don't have an hwnd, a context menu (if available) couldn't
access the text.

You have two alternatives:

1) use a text box directly, set to borderless, locked and with the
backcolour the same colour as the form? It will look like a label but the
user will be able to select/copy the text.

2) create / implement your own context menu. Design a hidden menu on the
form (mnuWhatever in this demo with one item - "Copy Text", menu name
mnuEdit, Index=0) and add code:


Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, x As
Single, Y As Single)

If Button = vbRightButton Then
PopupMenu mnuWhatever
End If

End Sub


Private Sub mnuEdit_Click(Index As Integer)

Select Case Index

Case 0 'copy
Clipboard.Clear
Clipboard.SetText Label1.Caption

'any other menu Case options here

Case Else

End Select

End Sub



--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




"Bryan Dickerson" <txprphan@xxxxxxxxxxxx> wrote in message
news:%23cIRsbHEGHA.3868@xxxxxxxxxxxxxxxxxxxxxxx
: I've Google-grouped for this and I found what looks to be an answer, but
it
: was in Spanish which is not my native tongue or my forte'...
:
: Can someone point me in the right direction to find out how to add the
: textbox context menu items to the label control. What I'm really looking
: for is the "Copy" item.
:
: TIA!
:
: --
: TFWBWY...A
:
:

.



Relevant Pages

  • Re: Textbox context menu on a label control
    ... > Since VB labels don't have an hwnd, a context menu couldn't ... > 2) create / implement your own context menu. ... > Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, x As ... textbox context menu items to the label control. ...
    (microsoft.public.vb.general.discussion)
  • Re: Dragging an object within container
    ... I want the user to be able to drag a label object around inside a ... has an HWnd, including forms. ... Private Const WM_NCLBUTTONDOWN = &HA1 ... Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As ...
    (comp.lang.basic.visual.misc)
  • RE: Control Tip Text Question
    ... --You didnt try the frame control..No problems. ... ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) ... Private Sub CheckBox470_MouseMove(ByVal Button As Integer, ... i only want the label to be seen if mouse is over the checkbox. ...
    (microsoft.public.excel.programming)
  • Re: Floating Box for Prices
    ... (to trigger your floating window for example). ... Label control indicates when the "mouse down for a specified period" has ... Private tDown As Single, counting As Boolean ... Private Sub Picture1_MouseDown(Button As Integer, ...
    (microsoft.public.vb.general.discussion)
  • Re: A HELP BOX
    ... lblDescriptive is the name of the descriptive label placed near the textbox. ... Private Sub UserForm_Initialize ... 'Show the decriptive label on entry to the text field. ... name, CtrlTab twice, your Middle Initial, CtrlTab once, Last Name""" ...
    (microsoft.public.word.vba.general)