创建分割条用户对条
(1)创建Standard Visual 用户对象,类型静态文本框(static text)并取名uo_splitbar保存
(2)定义uo_splitbar的实例变量:Instance Variables
//控件
Dragobject idrg_left,idrg_right
Dragobject idrg_up,idrg_down
boolean ib_mousedown = False//鼠标左键按下标志
char ic_vh_flag //竖直/水平标志
integer ii_barthickness = 20 //条的厚度
(3)定义uo_splitbar的内部函数并编写代码
of_setpointer() Return None //此函数用于设置鼠标形状,代码如下:
// 设置鼠标形状
Choose Case ic_vh_flag
Case 'V'
This.pointer = "SizeWE!"
Case 'H'
This.pointer = "SizeNS!"
Case Else
This.pointer = "Arrow!"
End Choose
of_setcontrols()
//参数
value dragobject adrg_1
value dragobject adrg_2
value character ac_vh_flag
//此函数用于注册要融合的控件
//函数功能:注册控件
//参数 adrg_1 分割条左或上控件
// adrg_2 分割条右或下控件
// ac_hv_flag竖直/水平标志
ic_vh_flag = Upper(ac_vh_flag) //竖直/水平标志
Choose Case ic_vh_flag
Case 'V' //竖直
idrg_left = adrg_1
idrg_right = adrg_2
//设置宽度
This.width = ii_barthickness
//以分割条为中民重新定义在左右控件的宽度
idrg_left.width = This.x - idrg_left.x
idrg_right.width = idrg_rigth.x + idrg_right.width - (This.x + This.width)
idrg_right.x = This.x +This.width
//以左边控件为基准重新定义分割条及右控件的高度
This.y = idrg_left.y
This.Height = idrg_left.Height
idrg_right.y = idrg_left.y
idrg_right.Height = idrg_left.Height
Case 'H' //水平
idrg_up = adrg_1
idrg_down = adrg_2
//设置宽度
This.Heigth = ii_barthickness
//以分割条为中心重新定义上下控件的高度
idrg_up.Height = This.y - idrg_up.y
idrg_down.Height = idrg_down.y + idrg_down.Height - (This.y + This.Height)
idrg_down.y = This.y + This.Height
//以左边控件为基准重新定义分割条及右控件的宽度
This.x = idrg_up.x
This.width = idrg_up.width
idrg_down.x = idrg_up.x
dirg_down.width = idrg_up.width
Case Else
End Choose
(4)定义uo_splitbar的用户事件
ue_lbuttondown :Event ID------pbm_lbuttondown
ue_mouse move :Event ID ----- pbm_mousemove
ue_lbuttonup :Event ID ------ pbm_lbuttonup
(5)在uo_splitbar的以下事件中编写脚本
Constructor 事件
of_setpointer()
this.width = ii_barthickness
this.backcolor = 67108864 // 背景颜色 Button Face
ue_lbuttondown 事件
of_setpointer()
ib_mousedown = True
This.BackColor = 134217731 //背景颜色 Inactive Title Bar
ue_mousemove 事件
integer li_x, li_y
//设置鼠标形状
of_setpointer()
IF ib_mousedown = False Then Return
SetPosition(ToToP!)
Choose Case ic_vh_flag
Case 'V' //竖直分割条
li_x = parent.DyNAMIC Pointerx()
//分割条的位置不能超过左控件的左边框和右控件的右边框
IF li_x<= idrg_left.x or li_x > = idrg_right.x + idrg_right.width Then Return
//在鼠标移动过程中,将分割条的横坐标设为鼠标的横坐标
this.x = li_x
Case 'H' //水平分割条
li_y = Parent.DyNAMIC PointerY()
//分割条的位置不能超过上控件的上边框和下控件的下边框
IF li_y <= idrg_up.y or li_y >= idrg_down.y + idrg_down.height Then Return
//在鼠标移动过程中将分割条的纵坐标设为鼠标的纵坐标
This.y = li_y
Case Else
Return
End Choose
ue_lbuttonup 事件
If ib_mousedown = False Then Return Else ib_mousedown = False
This.BackColor = 67108864 //背景色
Choose Case ic_vh_flag
Case 'V'
//以分割条为中心得新定义控件
idrg_left.width = This.x - idrg_left.x
idrg_right.Width = idrg_right.x + idrg_right.Width - (This.x + This.Width)
idrg_right.x + This.x + This.width
Case 'H'
idrg_up.Height = This.y - idrg_up.y
idrg_down.Height = idrg_down.y + dirg_down.Height - (This.y + This.Height)
idrg_down.y = This.y + This.Height
End Choose
使用分割条用户对象
(1)创建窗口并加入控件
st_splitbar UserObject 继承uo_splitbar 创建
tv_1 TreeView 置于分割条左边的控件
dw_1 DataWindow 置于分割条右边的控件
(2) 在窗口open事件中编写脚本
//注册要融合的控件
st_splitbar.of_setcontrols(tv_1,dw_1,'V')