Hi In my previous blog i shown to create a transparent windows form.In this post i am going to show how to drag the transparent windows form to any location.
Create a event handler for Picturebox(mouseup,mousedown and mousemove) and paste the following piece of code.
private void pictureBox1_MouseDown_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
drag = true;
x = Cursor.Position.X - this.Left;
y = Cursor.Position.Y - this.Top;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
drag = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (drag)
{
this.Top = System.Windows.Forms.Cursor.Position.Y - y;
this.Left = System.Windows.Forms.Cursor.Position.X - x;
}
this.Cursor = Cursors.Default;
}
Download source code from here.
Click here for my previous blog.
No comments:
Post a Comment