Question Toolstrip Textbox labels?

kriswinner

Member
Joined
Apr 23, 2009
Messages
23
Programming Experience
10+
Is it possible to have a label precede a toolstriptextbox?
If so...how?
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
Add a ToolStripLabel then add a ToolStripTextBox
 

kriswinner

Member
Joined
Apr 23, 2009
Messages
23
Programming Experience
10+
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.
 

kriswinner

Member
Joined
Apr 23, 2009
Messages
23
Programming Experience
10+
Ok...found the answer.
Thanks for the feedback. It led me in the right direction.

The code I modified was from here.

Code:
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...

Code:
            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
 
Top Bottom