Problem with moving a winform using C#

Posted by karthik on Stack Overflow See other posts from Stack Overflow or by karthik
Published on 2010-04-19T02:53:12Z Indexed on 2010/04/20 4:53 UTC
Read the original article Hit count: 205

Filed under:
|

My form doesn't have a title bar, so I am implementing the code to drag the entire form around the screen. I am using the below code to do it, which works fine. I have two panels in my form, PanelA and PanelB. During the startup I show PanelA where the dragging works perfectly. Later when the user clicks the button in PanelA, I need to make PanelA invisible and show PanelB However, the dragging does not work when PanelB is shown. What's the problem here?

private void SerialPortScanner_MouseUp(object sender, MouseEventArgs e)
{
    this.drag = false; 
}

private void SerialPortScanner_MouseDown(object sender, MouseEventArgs e)
{
    this.drag = true;
    this.start_point = new Point(e.X, e.Y);
}

private void SerialPortScanner_MouseMove(object sender, MouseEventArgs e)
{
    if (this.drag)
    {
        Point p1 = new Point(e.X, e.Y);
        Point p2 = this.PointToScreen(p1);
        Point p3 = new Point(p2.X - this.start_point.X,
                             p2.Y - this.start_point.Y);
        this.Location = p3;
    }
} 

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms