0

In window application, using c# i created one form and put visible false minimize, maximize button and formborder to none, i place one panel at top of the form, in that panel i place close, minimize buttons. Now how can i drag the window form. Any reference please. my code is

        this.ControlBox = false;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.FormBorderStyle = FormBorderStyle.None;

Thank you.

Ssasidhar
  • 475
  • 4
  • 12
  • 25

1 Answers1

0

Simply register the MouseDown, MouseMove and MoueUp events for your Panel

    bool MouseDownFlag = false;
    Point start = new Point(0, 0);

    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        start = new Point(e.X, e.Y);
        MouseDownFlag = true;
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (MouseDownFlag)
        {
            Point newPoint = new Point();
            newPoint.X = this.Location.X - (start.X - e.X);
            newPoint.Y = this.Location.Y - (start.Y - e.Y);

            this.Location = newPoint;
        }
    }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        MouseDownFlag = false;
    }
Mohsen Afshin
  • 13,273
  • 10
  • 65
  • 90
  • Hi Afshin, thanks for replying, how can i register events, is there any reference – Ssasidhar Oct 31 '12 at 03:49
  • In the Properties pane of your Form, in the Events section, double click on each of MouseDown, MouseMove, MouseUp events so that a method is generated automatically for each event, or in the Load event of your form add codes likes this.MouseDown += panel1_MouseDown; .... – Mohsen Afshin Oct 31 '12 at 06:28