实现窗体内部的左右移动

2/27/2006来源:Visual Basic教程人气:8725

'分割区的宽度
PRivateConstSPLITTERWIDTH=45
'最小移动宽度
PrivateConstHMIN=15
'picLeft和picRight的宽度相对于窗体的比例
PrivatePercentAsSingle
'正在拖动的标志
PrivateDragFlagAsBoolean

'每次拖动后需要重排窗体上的控件
PrivateSubRedrawMe()
DimNewWidthAsSingle
'忽略窗体缩小的情况
IfWindowState=vbMinimizedThenExitSub
NewWidth=(ScaleWidth-SPLITTERWIDTH)*Percent
Picleft.Move0,0,NewWidth,ScaleHeight
Picright.MoveNewWidth SPLITTERWIDTH,0,ScaleWidth-NewWidth-SPLITTERWIDTH,ScaleHeight
EndSub

PrivateSubForm_Load()
'PicLeft和PicRight的MousePointer=1
Percent=0.5
EndSub

PrivateSubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
DragFlag=True
EndSub

PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
'定义鼠标为vbSizeWE型
MousePointer=vbSizeWE
Percent=X/ScaleWidth
RedrawMe
EndSub

PrivateSubForm_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
DragFlag=False
MousePointer=0'此行语句实际没有起作用
EndSub->