日期:2014-05-20  浏览次数:20477 次

鼠标拖动控件
请问vs2003中怎样实现像VS设计器那样鼠标拖动控件的效果

------解决方案--------------------

//******************************************* Move **********************************************************//
// 功能:让日历可移动
// 编码:Dragon Deng
var IsMove = false;
var dragClickX = 0;
var dragClickY = 0;

function catchCalendar(e){
IsMove = true;
dragClickX=event.clientX-parseInt(crossobj.left);
dragClickY=event.clientY-parseInt(crossobj.top);
document.getElementById( "calendar ").setCapture();
document.onmousemove = moveCalendar;
}

function releaseCalendar(e){
IsMove = false;
document.getElementById( "calendar ").releaseCapture();
document.onmousemove = null;
hideElement( 'SELECT ', document.getElementById( "calendar ") );
hideElement( 'APPLET ', document.getElementById( "calendar ") );
popDownYear();
popDownMonth();
}

function moveCalendar(e){
if(IsMove){
crossobj.left =event.clientX-dragClickX;
crossobj.top = event.clientY-dragClickY;
crossobj.visible = 'show '

//test
var ary = GetElementPos(document.getElementById( 'calendar '));
if(ary[1] + 182 > document.body.clientHeight)
{
document.body.scrollTop += ary[1] + 182 - document.body.clientHeight
}
if(ary[0] + 191 > document.body.clientWidth)
{
var balance = ary[0] + 191 - document.body.clientWidth
window.body.scrollLeft(balance,0);
}
//end test
}

}
//
//******************************************* end ***********************************************************//