上面一种方法没停止控制啊!
没MouseUp怎么判断停止?

解决方案 »

  1.   

    我上面那个也有UP,没贴。
    public partial class Form1 : Form
        {
            System.Drawing.Region r = new Region(new Rectangle(0, 0, 50, 50));
            GraphicsPath myPath;
            Region myRegion;
            bool IsMouseDown = false;
            int EntryX, EntryY;
            int StartPosX, StartPosY;
            int tempX, tempY;
            Bitmap image1 = (Bitmap)Image.FromFile(@"C:\Documents and Settings\Adiministrater\My Documents\Visual Studio 2008\Projects\testGDI+\testGDI+\Resources\TutorLogo.jpg", true);
            TextureBrush Tb;
            int posX, posY;
            public Form1()
            { 
                Tb= new TextureBrush(image1);
                Tb.WrapMode = WrapMode.Clamp;
                tempX = StartPosX = 60;
                tempY = StartPosY = 60;
                tempX = StartPosX;
                tempY = StartPosY;
                myPath = new GraphicsPath();
                myPath.AddEllipse(StartPosX, StartPosY, 30, 30);
                myRegion = new Region(myPath);
                Tb.TranslateTransform(StartPosX, StartPosY);
                InitializeComponent();
                this.AutoScrollMinSize = new Size(1280,1024);
            }        private void Form1_Load(object sender, EventArgs e)
            {
     
            }        protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                Graphics g = e.Graphics;            //平移坐标系
                g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
                this.BackgroundImage = Properties.Resources.IMAGE_01副本;
            }
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                
                e.Graphics.FillRegion(Tb, myRegion);
                Tb.TranslateTransform(EntryX - posX, EntryY - posY);
            }
            private void Form1_MouseClick(object sender, MouseEventArgs e)
            {   
                MessageBox.Show(e.X.ToString() + " " + e.Y.ToString());
            }        private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if(myRegion.IsVisible(new Point(e.X, e.Y)))    
                    this.IsMouseDown = true;
                if (e.Button == MouseButtons.Left)
                {
                    
                    EntryX = e.X;
                    EntryY = e.Y; //MessageBox.Show(EntryX.ToString() + " " + EntryY.ToString());
                }
               
            }        private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                this.IsMouseDown = false;
                StartPosX = tempX;
                StartPosY = tempY;        }        private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (IsMouseDown && e.Button == MouseButtons.Left)
                {
                    tempX = StartPosX;
                    tempY = StartPosY;
                    
                    tempX += (e.X - EntryX);
                    tempY += (e.Y - EntryY);
                    posX = e.X;
                    posY = e.Y;
                    myPath = new GraphicsPath();
                    myPath.AddEllipse(tempX, tempY, 30, 30);
                    myRegion = new Region(myPath);
                    Tb.TranslateTransform(e.X - EntryX, e.Y - EntryY);
                    pictureBox1.Invalidate();
                    
                }
            }
    这是改过的能用的,之前写的那个Form1_MouseMove就不行,为什么