![]() MenuSourceControl = CType(sender, ContextMenuStrip).SourceControl ' set reference in case/before it is lost Private Sub cms_Opening(sender As Object, e As CancelEventArgs) Handles cms.Opening Under certain conditions the SourceControl can get lost but you can track it yourself with a variable and the parent ContextMenuStrip Opening event: S in the ContextMenuStrip, so you have to get the "parent" first:ĭim mi = CType(sender, ToolStripMenuItem)ĭim cms = CType(mi.Owner, ContextMenuStrip)Ĭonsole.WriteLine() Property which contains a reference to the control which opened the menu. KABOOM!")ĭebug.Print("debug info: tag contains data other than sender control. Private Sub ContextMenu_ItemClicked(sender As System.Object, e As ) Handles ContextMenu.ItemClickedĭebug.Print("debug info: forgot to set sender? well. If e.Button = ThenĪnd this is the code of the event handler when clicking a menu item: Private Sub TextBox1_MouseUp(sender As, e As ) Handles TextBox1.MouseUp The context menu is linked in TextBox1, so we need to add another event handler that saves the sending control into the menu: Okay, I found a solution that works fine, and here's the code for all VB.NET coders that have the same problem. It wouldn't understand an input from another type of window.) (The implementation, similarly, uses properties of the frame that are only set for a document instance. ![]() ![]() Once the focus is in Solution Explorer, it would determine that the command should not be enabled as Solution Explorer is not a document window. The implementation of this command's QueryStatus (I peeked) looks at the currently active WindowFrame, and requires that it be associated with an open document. In this case, QueryStatus is determining that the command should not be enabled. There's a lot of documentation about how commands work in VS, but to quickly paraphrase: command handlers implement an Execute method to do the operation and optionally a QueryStatus method to determine if the command is currently able to execute. However, you could implement your own handler for this command (or a brand new command with the same label). TL DR: You can't force the command handler to be enabled. Private Sub ChildToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ChildToolStripMenuItem.Clickĭim Strip As ContextMenuStrip = CType(sender, ToolStripMenuItem).OwnerItem.Owner Private Sub TestToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TestToolStripMenuItem.Clickĭim Strip As ContextMenuStrip = CType(sender, ToolStripMenuItem).Owner Me.ContextMenuStrip1.Tag = CType(Me.ContextMenuStrip1.SourceControl, Control) Private Sub ContextMenuStrip1_Opening(sender As Object, e As CancelEventArgs) Handles ContextMenuStrip1.Opening Me.TextBox2.ContextMenuStrip = Me.ContextMenuStrip1 Me.TextBox1.ContextMenuStrip = Me.ContextMenuStrip1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load The workaround presented there uses a private variable to store the If you check this C# thread the accepted answer notes it is a bug.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |