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);
当我尝试拖动图像时,我没有让图像移动,这与我认为的鼠标按下方法有关我本质上想要:以便能够向下点击拖动带有图像的矩形 我已创建然后当左按钮松开以使图像消失时
下面是一个例子。它使用包含带有Image
的PictureBox
的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();
}