I need to programatically (dynamically) raise a specific contextmenustrip item called "Edit parameters" for controls on a Windows form (user GUI). The loop below shows how the controls are looped over, and how the contextmenustrip items for each control are filtered for an "Edit" item, and then that item is dynamically fired. The problem is that the user control is also visible -- which is the typical operation when a user wants to edit parameters -- that is, show the user control after right-clicking on the control's contextmenustrip item.
Is there a way to (a) programatically load the user control (when the contextmenustrip item called "Edit parameters" is dynamically selected) , and then (b) select the "Apply" button, without making the user control visible? All of this dynamic programming is performed to programatically raise all of the "Edit parameters" contectmenustrips, which spawns the user control, and then selects the apply button button. There is actually no way to use default user control options in a separate method because every time the user changes the parameters, the controls and parameter values are serialized -- so yes, serializing is also being done. However, the major issue is that I don't want the contextmenustrips to be visible during dynamic spawning and I don't want the user control to be visible when the "Edit parameters" item of the contextmenustrip is dynamically selected.
How can this be done when keeping contextmenustrips invisible and user controls invisible?
The code below loops through each control's (in Me.Controls) contextmenustrip items to determine if an "Edit" item is found, and then raises the UC dynamically:
For Each ctitem In nxgContextMenuStrip.Items
If InStr(ctitem.Text, "Edit") > 0 Then
CurrentUCForm.Visible = False
Dim btn As Button = CurrentUCForm.Controls("ApplyButton")
The code below raises the UC when the contextmenustrip item called "Edit parameters" of each control in Me.Controls is dynamically selected in the loop above. Problem is, the UC is not invisible to the user.
Dim myform As New Form
myuc.autosize = True
myform.AutoSize = True
myform.Dock = DockStyle.Fill
myform.Width = 0
myform.Height = 0
myform.Width = myuc.width
myform.Height = myuc.height + 50
myform.Left = 0
If runbuttonclicked = 1 Then myform.Visible = False 'this does not hide the UC
myform.Top = 0
Dim btn As New Button
btn.Text = "Apply"
btn.Top = 10 ' myform.Bottom - 50
btn.Left = 10 ' myform.Left + 10 'myform.Right - 60
btn.Name = "ApplyButton"