Results 1 to 5 of 5

Thread: Toolstrip Textbox labels?

  1. #1
    kriswinner is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2009
    Posts
    23
    Reputation
    52

    Toolstrip Textbox labels?

    Is it possible to have a label precede a toolstriptextbox?
    If so...how?

  2. #2
    JuggaloBrotha's Avatar
    JuggaloBrotha is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,321
    Reputation
    959
    Add a ToolStripLabel then add a ToolStripTextBox
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.


  3. #3
    kriswinner is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2009
    Posts
    23
    Reputation
    52
    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.

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,176
    Reputation
    2368
    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.

  5. #5
    kriswinner is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2009
    Posts
    23
    Reputation
    52
    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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking