Click here to Skip to main content
16,016,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone help me a little bit here. The issue is when I right click on the form, my contextmenustrip appears with a new control I added and it accepts a value and passes it through an add handler. The issue is once I have that value, I can't see the instantiated form nor can I close down the context menu strip as it is not visible.

Public Class Form1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        cmenuListView.Items.Add(New MyToolStripItem)

    End Sub

    Private Sub FilterBySymbolToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FilterBySymbolToolStripMenuItem.Click
        MessageBox.Show("Filter By Symbol Ver 1 worked")
    End Sub

    Public Class MyToolStripItem
        Inherits ToolStripControlHost

        Public Sub New()
            MyBase.New(New MyToolbarControl)
        End Sub

        Public ReadOnly Property MyToolbarControlProp() As MyToolbarControl
            Get
                Return CType(Control, MyToolbarControl)
            End Get
        End Property

        Protected Overrides Sub OnSubscribeControlEvents(ByVal control As Control)

            MyBase.OnSubscribeControlEvents(control)

            Dim myToolbarControlProp As MyToolbarControl = _
            CType(control, MyToolbarControl)

            AddHandler myToolbarControlProp.MyTxt.KeyDown, AddressOf HandleMarkChange

        End Sub
        Protected Overrides Sub OnUnsubscribeControlEvents(ByVal control As Control)

            MyBase.OnUnsubscribeControlEvents(control)

            Dim myToolbarControlProp As MyToolbarControl = _
            CType(control, MyToolbarControl)

            RemoveHandler myToolbarControlProp.MyTxt.KeyDown, AddressOf HandleMarkChange

        End Sub
        Public Sub HandleMarkChange(ByVal sender As Object, ByVal e As KeyEventArgs)

            If e.KeyCode = Keys.Enter Then

                Dim MyValue As String = DirectCast(sender, TextBox).Text

                MyToolbarControlProp.MyTxt.Text = String.Empty

                MsgBox(MyValue)

                'now need to run code against another control on form but can't see instantiated form

                'add code

                'now also need to close cmenuListView but can't see .close - CAUSES ERROR
                'cmenuListView.close()

            End If

        End Sub
    End Class

    Public Class MyToolbarControl
        Inherits ToolStripContentPanel

        Friend WithEvents MyTxt As New TextBox
        Friend WithEvents MyLbl As New Label

        Public Sub New()
            MyBase.Size = New System.Drawing.Size(175, 20)
            MyBase.BackColor = Color.Empty

            With MyLbl
                .Anchor = AnchorStyles.Bottom
                .Text = "Filter By Symbol:"
                .TextAlign = ContentAlignment.BottomLeft
                '.Size = New Size(60, 15) ' Filter For:
                .Size = New Size(90, 15)
                .Location = New Point(0, 0)
                .Parent = Me
            End With

            With MyTxt
                .Anchor = AnchorStyles.Right
                .Location = New Point(MyLbl.Right, 0)
                .Width = Width - MyTxt.Left
                .AcceptsReturn = True
                .AcceptsTab = True
                .Enabled = True
                .ReadOnly = False
                .Parent = Me
            End With

        End Sub

    End Class

End Class
Posted
Updated 8-Dec-09 14:22pm
v2

Try to redraw and refresh your form and contexmenu after you've added the object.
it worked for me.

What is : FilterBySymbolToolStripMenuItem_Click

Is it a toolstrip menu? i'm trying to recreate your project.

Also please don't post a new answer, update or edit you original question and add to the bottom. Otherwise the Q&A Reads harder for other people. :rolleyes:
 
Share this answer
 
v3
did you get it to work by me.refresh in the constructor? doesn't seem to work for me?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900