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
FilterBySymbolToolStripMenuItem_Click
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)