How to display (ToolStrip1) with the Mouse Right click On the special control

Mansour_Dalir 2,036 Reputation points
2023-06-12T04:33:31.8466667+00:00

enter image description here

hi

I want it to be displayed on the My Control Example Show By Button

Like (ContextMenuStrip), which can be displayed freely in the form by special control

        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)
        Dim dropDownButton As New ToolStripDropDownButton("Items")
        Dim host As New ToolStripControlHost(panel1)
        dropDownButton.DropDown = New ToolStripDropDown()
        dropDownButton.DropDown.Items.Add(host)
        ToolStrip1.Items.Add(dropDownButton)
Developer technologies | VB
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-06-12T06:31:27.7133333+00:00

    Hi @Mansour_Dalir ,

    You can refer to the following code to add a right-click menu for the control you want.

    1. Add a ContextMenuStrip to the form, named ContextMenuStrip1
    2. 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.
    3. 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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.