tags:

views:

653

answers:

4

In a WinForms .Net 2.0 application, I want to create a context menu with a ToolStripMenuItem that has both a label AND a textbox in the item itself. An example of what I am talking about can be found in Access - when viewing an Access table, the context menu has options for "Filter By Selection", "Filter Excluding Selection", and then "Filter For: _ _ _ _ _ _". This third option is essentially a label AND a text box in a single item. This is what I can't figure out how to do.

I've had no problem implementing this with two separate ToolStripMenuItems - one for the text, then a child with just the text box. But this is awkward and not as nice looking as the implementation in Access.

Can anyone point me in the right direction on this? I'm having trouble searching, as all everything I find seems to relate to context menus on a text box itself.

A: 

Here's a picture of what Rob3C's looking for: Access Context Menu

attack
+1  A: 

Here is an answere for you:

How to: Wrap a Windows Forms Control with ToolStripControlHost
ToolStripControlHost Class

And, a short demo i wrote (bare in mind it looks horrid as i havent styled it at all):

(VB.net as i prefer that, and you didnt specify which language you prefered)

Public Class ToolStripEntry
    Inherits ToolStripControlHost

    Public Sub New()
        MyBase.New(New ControlPanel)

    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  //with events so you can just use the events
    Friend WithEvents lbl As New Label    //don think you can just do that in c#, but you get the idea

    Public Sub New()

        lbl.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Bottom
        lbl.Text = "Test"
        lbl.TextAlign = ContentAlignment.MiddleLeft
        lbl.Size = New Size(30, Me.Height)          //think of somthing!
        lbl.Location = New Point(0, 0)
        lbl.Parent = Me

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

    End Sub

End Class
Pondidum
Thanks Andy! Exactly what I was looking for. I hate it when the answer is right there in the docs and I just missed it. Thanks for the link and example.
Rob3C
A: 

that's a very good Idea!!

bikelink
A: 

how can you connect that to an existing contextmenustrip

mark
when i do it creates a panel in the menu that is wide - not like a normal toolstripitem
mark