|
发表于 2020-3-26 16:15:01
|
显示全部楼层
private Point mousePosition = new Point(0, 0);
public Form1()
{
InitializeComponent();
}
private void minPanel_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.minPanel.CreateGraphics();
Image img = Image.FromFile(Application.StartupPath + @"\7.jpg");
g.DrawImage(img, this.minPanel.ClientRectangle, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
}
private void minPanel_MouseDown(object sender, MouseEventArgs e)
{
this.controlframe.Left = e.X;
this.controlframe.Top = e.Y;
DrawBig();
DrawSmall();
}
private void controlframe_Paint(object sender, PaintEventArgs e)
{
DrawSmall();
}
private void controlframe_MouseUp(object sender, MouseEventArgs e)
{
DrawSmall();
DrawBig();
}
private void controlframe_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.X >= 0 && e.X <= this.minPanel.ClientRectangle.Width && e.Y >= 0 && e.Y <= this.minPanel.ClientRectangle.Height)
{
this.controlframe.Left = e.X + this.mousePosition.X;
this.controlframe.Top = e.Y + this.mousePosition.Y;
DrawSmall();
DrawBig();
}
}
}
private void controlframe_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.mousePosition.X = this.controlframe.Left;
this.mousePosition.Y = this.controlframe.Top;
this.DrawSmall();
this.DrawBig();
//this.Dispose;
}
}
private void DrawSmall()
{
Graphics g = this.controlframe.CreateGraphics();
Bitmap bmp = new Bitmap((Bitmap)Bitmap.FromFile(Application.StartupPath + @"\7.jpg"), new Size(this.minPanel.Width, this.minPanel.Height));
g.DrawImage(bmp, this.controlframe.ClientRectangle, this.controlframe.Left, this.controlframe.Top, this.controlframe.ClientRectangle.Width, this.controlframe.ClientRectangle.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
this.controlframe.Update();
}
private void DrawBig()
{
Graphics g = this.maxPanel.CreateGraphics();
Image img = Image.FromFile(Application.StartupPath + @"\7.jpg");
g.DrawImage(img, this.maxPanel.ClientRectangle, this.controlframe.Left, this.controlframe.Top, this.maxPanel.ClientRectangle.Width, this.maxPanel.ClientRectangle.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
this.minPanel.Update();
} |
|