Hi @Mansour_Dalir ,
You can refer to the following code to add a right-click menu for the control you want.
- Add a ContextMenuStrip to the form, named ContextMenuStrip1
- Find the ContextMenuStrip property in the properties panel of the control where you want to add the right-click menu and set it to ContextMenuStrip1.
- Use the following code to add the desired controls to the ContextMenuStrip1.
Dim listBox1 As New CheckedListBox()
Dim Button1 As New Button()
Dim panel1 As New Panel()
panel1.Width = 400
panel1.Controls.Add(Button1)
panel1.Controls.Add(listBox1)
listBox1.Items.Add("A")
listBox1.Items.Add("B")
listBox1.Items.Add("c")
listBox1.Items.Add("d")
Button1.Width = 50
Button1.Text = "OK"
Button1.Location = New Point(20, 150)
ContextMenuStrip1.Items.Add(New ToolStripControlHost(listBox1))
ContextMenuStrip1.Items.Add(New ToolStripControlHost(Button1))
ContextMenuStrip1.Items.Add(New ToolStripControlHost(panel1))
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.