问大家一个问题,我有一个WinForm窗体中,容体中有一个tablelayoutpanel控件,有一个button控件,button可以在窗体上移动,让button移动到tablelayoutpanel的工作区内,就被自动吸附到表格里 private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            p = new Point(e.X, e.Y);
        }        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.button1.Location = new Point(e.X - p.X + this.button1.Left, e.Y - p.Y + this.button1.Top);
                if (this.button1.Left < 0 || this.button1.Right > this.Width || this.button1.Top < 0 || this.button1.Bottom > this.Height)
                {
                    this.button1.Location = new Point(0, 0);
                }
            }
            else
            {
                this.button1.Cursor = Cursors.Hand;
            }
}以上环境在vs2005

解决方案 »

  1.   

    winfrom的问题怎么发到asp.net上了呢??
      

  2.   

    javascript可以SCRIPT LANGUAGE="JavaScript">
    <!--
    var currentMoveObj = null;    //当前拖动对象
    var relLeft;    //鼠标按下位置相对对象位置
    var relTop;
    function f_mdown(obj)
    {
        currentMoveObj = obj;        //当对象被按下时,记录该对象
        currentMoveObj.style.position = "absolute";
        relLeft = event.x - currentMoveObj.style.pixelLeft;
        relTop = event.y - currentMoveObj.style.pixelTop;
    }
    window.document.onmouseup = function()
    {
        currentMoveObj = null;    //当鼠标释放时同时释放拖动对象
    }
    function f_move(obj)
    {
        if(currentMoveObj != null)
        {
            currentMoveObj.style.pixelLeft=event.x-relLeft;
            currentMoveObj.style.pixelTop=event.y-relTop;
        }
    }//-->
    </SCRIPT>
    <BODY>
    <TABLE width="100" border=1 onselectstart="return false" style="position:absolute;left:50;top:50" onmousedown="f_mdown(this)" onmousemove="f_move(this)">
    <TR>
        <TD bgcolor="#CCCCCC" align="center" style="cursor:move">title1</TD>
    </TR>
    <TR>
        <TD align="center" height="60">content</TD>
    </TR>
    </TABLE>
    <TABLE width="100" border=1 onselectstart="return false" style="position:absolute;left:350;top:250" onmousedown="f_mdown(this)" onmousemove="f_move(this)">
    <TR>
        <TD bgcolor="#CCCCCC" align="center" style="cursor:move">title2</TD>
    </TR>
    <TR>
        <TD align="center" height="60">content</TD>
    </TR>
    </TABLE>
    </BODY>
      

  3.   

    如果在winform上,做,有什么好的方法吗,我觉得不是很好实现啊