我写了个控件
想让他运行的时候可以按下鼠标可以被鼠标拖动
并且让控件覆盖的地域成为控件的背景  怎么作到呢
 大家有知道的或者有什么方法的 
请指导一下啊 多谢拉

解决方案 »

  1.   

    这个需要重写MouseDown和MouseUp事件
    我来写个简单的吧
    我这里用继承自Form的用户控件
    其它的用户控件也没什么不同的int x = 0;
    int y = 0;
    bool isMoving = false;protected void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    {
    isMoving = true;
    x = e.X;
    y = e.Y;
    }
    }protected void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(isMoveable && e.Button == MouseButtons.Left && y < 29)
    this.Location = new Point(this.Location.X - x + e.X,this.Location.Y - y + e.Y);
    }protected void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    isMoving = false;
    }
      

  2.   

    谢谢这位高手的帮忙 那请问你知道怎么把这个空间所覆盖的地方设置为他的背景吗?
    或者说不让他覆盖Form1下面的图片 感觉就是这个控件好象是透明的 那样的感觉
    怎么做到呢
      

  3.   


    在你的自定义类型的构造函数中加上:
    SetStyle(ControlStyles.SupportsTransparentBackColor, true);
    this.BackColor = Color.Transparent;
    就可以透明了