Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Sorry I said wront control name on my first question.I set the border style to none.But I want to add Menustrip for my form. I changed background ımage of form and also added a picturebox to top of my form .this is works for my form looks like real window.and I also handling Click event of picturebox when user clicks my picturebox its moving the form.but when I want to add menu strip to my form its going under of my picturebox.so I want to change location of menu strip.
Sorry for my Mistakes and bad english.
Posted
Updated 15-Jan-12 12:34pm
v3
Comments
Emad Al Hawary 15-Jan-12 0:17am    
try this:

contextMenuStrip1.Show(treeView1, new Point(treeView1.SelectedNode.Bounds.X, treeView1.SelectedNode.Bounds.Y));
BillWoodruff 15-Jan-12 0:21am    
I find the scenario you describe very confusing:

1. you have a PictureBox on top of a Form: is that PictureBox a Control which is part of the Form: if not, what container (Form ? UserControl ?) is it in.

2. Why would you use a PictureBox to move a Form: does the Form itself have no TitleBar that would let you drag it around the usual way.

3. What is it exactly you want to add a ContextMenu to: the PictureBox ? the Form ?

If you clearly describe what you are trying to do here, I think you'll get some good answers.
opcoder123 15-Jan-12 18:43pm    
İt is not a UserControl.it is a winform but its not have borders.So when I set the borders to none I can't move my form like default forms.So I added a picture that allow me to move form when I click on it.but also I want to add menu strip like mfc menus.but I cant see it because there is a picturebox on top of the form.

Sorry for wasting your time.the problem was anchor property of menu strip item. I set it to top,left,bottom,right and my problem is solved.
 
Share this answer
 
Here is what you are looking for, just modify the code as you want.

VB
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ContextMenuStrip1.Show(Me, Button3.Location, ToolStripDropDownDirection.BelowRight)
    End Sub


this code shows menu strip on the button click you can change it.
 
Share this answer
 
v2
You can easily make a Form movable by implementing MouseDown, MouseUp, and MouseMove handlers. You could make it movable only when some special key is held down, or when you use the context-click mouse-button rather than the default, etc. To achieve this you will need to start by clicking on some portion of the Form that is not covered by a Control.

You could even click-drag on a MenuStrip to move the Form around, utilizing the same Events for the MenuStrip: of course you'll need to be starting the move by clicking on a portion of the MenuStrip that is not "covered" by a Control in the MenuStrip. For example:
private bool IsMouseUp = true;

private int mX;
private int mY;

private void menuStrip1_MouseDown(object sender, MouseEventArgs e)
{
    IsMouseUp = false;
    // note these co-ordinates will be in MenuStrip co-ordinate space
    mX = e.X;
    mY = e.Y;
}

private void menuStrip1_MouseUp(object sender, MouseEventArgs e)
{
    IsMouseUp = true;
}

private void menuStrip1_MouseMove(object sender, MouseEventArgs e)
{
    if (IsMouseUp) return;

    // note "this" will refer to the Form here
    // note e.X, and e.Y co-ordinates will be in MenuStrip co-ordinate space
    // we're just calculating an offset that we can use to move the Form
    this.Left += e.X - mX;
    this.Top += e.Y - mY;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900