图片拖动实现不了拉
嘿嘿 今天弄了个图片框小程序,我想法很简单就是是一个比图片框大的图片通过鼠标拖动,可以看到图片被遮住的部分。可是实现不了,也没有提示什么错误,希望高手能帮忙看看。
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication8
{
public partial class Form1 : Form
{
PictureBox pb;
Bitmap bmp,lion;//lion是原图片,bmp是lion在图片框内的部分。
int x1, y1, x2, y2,stpointx,stpointy,x,y;//stpointx,stpointy是图片框内的图片bmp左上角对应的在lion中的坐标,x1,x2,x3,x4分别对应鼠标的按下和弹起时的坐标。x,y为在X和Y方向拖动量。
bool dragstart = false;
public Form1()
{
this.SuspendLayout();
this.Size = new Size(400,400);
lion = (Bitmap)Bitmap.FromFile(@ "..\..\Resources\Water lilies.jpg ");
pb = new PictureBox();
pb.Size = new Size(300,300);
bmp = new Bitmap(pb.Width,pb.Height);
pb.BorderStyle = BorderStyle.Fixed3D;
pb.BackgroundImage = Bitmap.FromFile(@ "..\..\Resources\Water lilies.jpg ");
pb.Location = new Point((int)(this.ClientSize.Width * 0.5 - pb.Width * 0.5), (int)(this.ClientSize.Height * 0.5 - pb.Height * 0.5));
this.Controls.AddRange(new Control[] { pb});
this.ResumeLayout();
pb.MouseDown += new MouseEventHandler(pb_MouseDown);
pb.MouseUp += new MouseEventHandler(pb_MouseUp);
pb.MouseEnter += new EventHandler(pb_MouseEnter);
pb.MouseLeave += new EventHandler(pb_MouseLeave);