Question Can a Forms ContextMenu reference a UserControl's MenuItem

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
I have a ToolStripMenuItem in ContextMenuStrip Items on a UserControl that I'd like to reference in the Forms ContextMenuStrip items.

Is that possible?

P.S.

Presently the Form has its own MenuItem that calls it a UserControl Public Sub that performs the task the UserControl's ToolStripMenuItem performs.
I'd like to get rid of that sub as it's not consistent with the way I pass DropDown Properties of the userControl to the Form.
 
Expose it as a property of the usercontrol ?
 
I shortened the names for this post.

VB.NET:
'In the UserControl:

  Public ReadOnly Property GetQ() As ToolStripMenuItem
      Get
          Return Me.ToolStripMenuItem_General_CollapseAll
      End Get
  End Property


'In a Usercontrol that contained the first mentioned UserControl:

 Public ReadOnly Property GetQ() As ToolStripMenuItem
     Get
         Return Me.ControlDirAndFileExplorer_1.GetQ
     End Get
 End Property


'In the Form that contains the second mentioned usercontrol:

 Dim Q As ToolStripMenuItem = Me.ControlDisplayFilesNamesInCheckedDirs_1.GetQ
 Me.ToolStripMenuItem_Explorer_Checked.DropDown.Items.Add(Q)

RESULT:

The MenuItem no longer appears on the first mentioned UserControl'S ContextMenuStrip and does NOT appear on the forms MenuStrip's ToolStripMenuItem drop down.

Did I do as was suggested?
 
Last edited:
I knew that. I was hoping someone found a way around it.
I thought maybe, if no one had already found a way, I'd try usung reflection to get the event handler from the menuitem and pass that up to the form to be added to a form's menuitem.
 

Latest posts

Back
Top