创建一种方法,当我单击图片框时,它允许您拖动鼠标可以在表单周围拖动的克隆图像?
Create a method that when I click on a picturebox it allows you to drag a clone image that the mouse can drag around the form?
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Graphics gs = this.CreateGraphics();
Bitmap bimage = new Bitmap(pictureBox1.Image);
Rectangle rect = new Rectangle(e.X, e.Y, 200, 200);
TextureBrush tb = new TextureBrush(bimage);
gs.FillRectangle(tb, rect);
当我试图拖动图像时,我没有让图像移动,我认为这与 mousedown 方法有关
我基本上想要:
能够点击下来
拖动带有我创建的图像的矩形
然后松开左键图像消失
这是一个例子。它使用包含 PictureBox
和 Image
的 Form
。
Form form2 = new Form();
Point mdown = Point.Empty;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mdown = e.Location;
form2.BackgroundImage = pictureBox1.Image;
form2.Opacity = 0.5f;
form2.MaximizeBox = false;
form2.ControlBox = false;
form2.Text = "";
form2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form2.Size = pictureBox1.Image.Size;
form2.Show();
Point pt = pictureBox1.PointToScreen(pictureBox1.Location);
form2.Location = pt;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
form2.Location = pictureBox1.PointToScreen(
new Point(e.X -mdown.X, e.Y - mdown.Y ));
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
form2.Hide();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Graphics gs = this.CreateGraphics();
Bitmap bimage = new Bitmap(pictureBox1.Image);
Rectangle rect = new Rectangle(e.X, e.Y, 200, 200);
TextureBrush tb = new TextureBrush(bimage);
gs.FillRectangle(tb, rect);
当我试图拖动图像时,我没有让图像移动,我认为这与 mousedown 方法有关 我基本上想要: 能够点击下来 拖动带有我创建的图像的矩形 然后松开左键图像消失
这是一个例子。它使用包含 PictureBox
和 Image
的 Form
。
Form form2 = new Form();
Point mdown = Point.Empty;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mdown = e.Location;
form2.BackgroundImage = pictureBox1.Image;
form2.Opacity = 0.5f;
form2.MaximizeBox = false;
form2.ControlBox = false;
form2.Text = "";
form2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form2.Size = pictureBox1.Image.Size;
form2.Show();
Point pt = pictureBox1.PointToScreen(pictureBox1.Location);
form2.Location = pt;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
form2.Location = pictureBox1.PointToScreen(
new Point(e.X -mdown.X, e.Y - mdown.Y ));
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
form2.Hide();
}