3

I want to create a context menu using C# that will display next to the node similar to what happens here in Visual Studio:

The code I have now causes the main form to flicker.

private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        var myForm = new Form {Text = "My Form"};
        myForm.SetBounds(10, 10, 200, 200);

        myForm.Show();
        // Determine if the form is modal.
        if (myForm.Modal == false)
        {
            // Change borderstyle and make it not a top level window.
            myForm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            myForm.TopLevel = false;
        }
    }            
}
ardila
  • 1,277
  • 1
  • 13
  • 24
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188

3 Answers3

21

Why not simply use Form.ShowDialog?

From MSDN:

Form.ShowDialog Method

Shows the form as a modal dialog box.

Bruno Brant
  • 8,226
  • 7
  • 45
  • 90
1

You should set up treeView1.ContextMenu instead of the approach you're taking.

Tim S.
  • 55,448
  • 7
  • 96
  • 122
0

You should read and try ContextMenu control of c#. I think it will resolve your problem rather than the technique you used..... Or other than use, myform.showdialog(); with setbounds() methods.

Talha
  • 18,898
  • 8
  • 49
  • 66