星期六

.net中实现拖拽控件
        private int tX = 0;
        
private int tY = 0;

        
private void btn_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        
{
            
this.tX = e.X;
            
this.tY = e.Y;
            
this.btn.MouseMove += new System.Windows.Forms.MouseEventHandler(this.btn_MouseMove);
        }


        
private void btn_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        
{
            
this.btn.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.btn_MouseMove);
        }


        
private void btn_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        
{
            
this.btn.Location = new System.Drawing.Point(this.btn.Location.X + e.X - this.tX, this.btn.Location.Y + e.Y - this.tY);
        }

posted on 2006-08-11 11:02  星期六  阅读(954)  评论(0编辑  收藏  举报