Question Toolstrip Textbox labels?

Sorry...wrong terminology on my part.

Is there a way to do this within a MenuStrip?
I don't see the option of adding a label. I'd like to have a menu item with a label followed by a textbox (on the same line).

Thanks.
 
Short answer, no, but you can add ToolTipText.
Long answer, yes, you can create a user control that contains Label and Textbox and host it in MenuStrip using ToolStripControlHost.
 
Ok...found the answer.
Thanks for the feedback. It led me in the right direction.

The code I modified was from here.

VB.NET:
Public Class ToolStripTextBoxWithLabel
    Inherits ToolStripControlHost

    Public Sub New(Optional ByVal lblText As String = "label")
        MyBase.New(New ControlPanel(lblText))

    End Sub

    Public ReadOnly Property ControlPanelControl() As ControlPanel
        Get
            Return CType(Me.Control, ControlPanel)
        End Get
    End Property

End Class


Public Class ControlPanel
    Inherits Panel

    Friend WithEvents txt As New TextBox
    Friend WithEvents lbl As New Label

    Public Sub New(ByVal lblText As String)

        Me.Height = 20

        lbl.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Bottom
        lbl.Text = lblText
        lbl.TextAlign = ContentAlignment.BottomLeft
        lbl.AutoSize = True
        lbl.Height = Me.Height
        lbl.Location = New Point(0, 3)
        lbl.Parent = Me

        txt.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
        txt.Location = New Point(lbl.Right + 3, 0)
        txt.Width = Me.Width - txt.Left
        txt.Parent = Me

    End Sub

End Class

And here's how to call it...

VB.NET:
            Dim tb_LicenseKey As New ToolStripTextBoxWithLabel("License Key:")
            tb_LicenseKey.Name = "tb_LicenseKey"
            OptionMenu.DropDownItems.Add(New ToolStripSeparator)
            OptionMenu.DropDownItems.Add(tb_LicenseKey)
            tb_LicenseKey.BackColor = Color.FromArgb(246, 246, 246)

In my application, OptionMenu is a ToolStripMenuItem.

If anyone has any suggestions to improve this, please let me know and I'll update the posting.
Again...thanks for the input.

- KW
 
Back
Top