窗口上放一个分隔条,随着分隔条的左右移动,左右两边控件的宽度随着变化,PB中如何实现啊?
问题如标题,论坛里出现过相关的帖子,但是没看明白。是否可以直接提供源码,万分感谢!!
[解决办法]
$PBExportHeader$lht_vo_splitter.sru
$PBExportComments$分割条
forward
global type lht_vo_splitter from uo_statictext
end type
end forward
global type lht_vo_splitter from uo_statictext
integer width = 82
integer height = 240
integer textsize = -8
fontcharset fontcharset = ansi!
fontfamily fontfamily = roman!
string facename = "Times New Roman"
boolean focusrectangle = false
integer i_uid = 0
integer tipicon = 0
boolean havefocusrect = true
rowfocusind tooltiptype = hand!
boolean 透明 = false
event ue_lbuttondown pbm_lbuttondown
event ue_lbuttonup pbm_lbuttonup
event ue_drag ( long oldx, long oldy )
event ue_rbuttonup pbm_rbuttonup
end type
global lht_vo_splitter lht_vo_splitter
type prototypes
function ulong SetCapture(ulong hwnd)library "user32.dll"
function ulong ReleaseCapture() library "user32.dll"
end prototypes
type variables
long il_distance = 6
boolean ib_live = true
protected:
userobject iuo_1, iuo_2
boolean ib_vertical = true
boolean mousedown = false
long oldxpos,oldypos
end variables
forward prototypes
public subroutine of_setpointer ()
public subroutine of_setleftright (readonly graphicobject ago_l, readonly graphicobject ago_r)
public subroutine of_setupdown (readonly graphicobject ago_u, readonly graphicobject ago_d)
public subroutine of_resize ()
public subroutine of_resize (integer ai)
public subroutine of_setleftright (readonly graphicobject ago_l, readonly graphicobject ago_r, integer ai)
public subroutine of_setupdown (readonly graphicobject ago_u, readonly graphicobject ago_d, integer ai)
end prototypes
event ue_lbuttondown;ulong hnd
mousedown = true
oldxpos = unitstopixels( xpos, xunitstopixels! )
oldypos = unitstopixels( ypos, yunitstopixels! )
this.bringtotop = true
this.border = false
hnd = handle(this)
SetCapture(hnd)
if not ib_live then
this.backcolor = f_invert_color(this.backcolor)
end if
end event
event ue_lbuttonup;mousedown = false
ReleaseCapture()
if not ib_live then
this.backcolor = f_invert_color(this.backcolor)
this.post event ue_drag( iuo_1.x, iuo_1.y )
//iuo_2.setredraw( false )
if ib_vertical then
iuo_1.width = this.x - iuo_1.x
iuo_2.width = iuo_2.x + iuo_2.width - this.x - this.width
iuo_2.x = this.x + this.width
else
iuo_1.height = this.y - iuo_1.y
iuo_2.height = iuo_2.y + iuo_2.height - this.y - this.height
iuo_2.y = this.y + this.height
end if
iuo_1.triggerevent("ue_aftersize")
//iuo_2.setredraw( true )
end if
end event
event ue_rbuttonup;//
end event
public subroutine of_setpointer ();if isvalid( iuo_1 ) or isvalid( iuo_2 ) then
if ib_vertical then
this.pointer = "SizeWE!"
else
this.pointer = "SizeNS!"
end if
else
this.pointer = "Arrow!"
end if
end subroutine
public subroutine of_setleftright (readonly graphicobject ago_l, readonly graphicobject ago_r);of_setleftright(ago_l, ago_r, 2)
end subroutine
public subroutine of_setupdown (readonly graphicobject ago_u, readonly graphicobject ago_d);of_setupdown(ago_u, ago_d, 2)
end subroutine
public subroutine of_resize ();//默认为以右边或下方的控件为基准
of_resize(2)
end subroutine
public subroutine of_resize (integer ai);//====================================================================
// 过程(函数
[解决办法]
Function): lht_vo_splitter::of_resize()
//--------------------------------
// 描述(Description):
//--------------------------------
// 变量(Arguments):
//valueintegerai1表示按左边或者上方的控件的设置分隔栏的高度或宽度
//1表示按右边或者下方的控件的设置分隔栏的高度或宽度
//--------------------------------
// 返回(Returns): (none)
//--------------------------------
// 作者(Author):
//--------------------------------
// 修改历史(Modify History):
//
//--------------------------------
//
//====================================================================
if not isvalid(iuo_1) or not isvalid(iuo_2) then return
of_setpointer()
if ib_vertical then
if ai = 1 then
this.y = iuo_1.y
this.height = iuo_1.height
else
this.y = iuo_2.y
this.height = iuo_2.height
end if
this.x = iuo_1.x + iuo_1.width
long ll_w
ll_w = width
this.width = min(iuo_2.x - this.x, width)
if width <= 0 then width = ll_w
else
if ai = 1 then
this.x = iuo_1.x
this.width = iuo_1.width
else
this.x = iuo_2.x
this.width = iuo_2.width
end if
this.x = iuo_2.x
this.width = iuo_2.width
this.y = iuo_1.y + iuo_1.height
long ll_h
ll_h = height
this.height = min(iuo_2.y - this.y, height)
if height <= 0 then height = ll_h
end if
end subroutine
public subroutine of_setleftright (readonly graphicobject ago_l, readonly graphicobject ago_r, integer ai);//if isvalid(iuo_1) then return
iuo_1 = ago_l
iuo_2 = ago_r
ib_vertical = true
of_resize( ai)
this.tag = '在这里按住鼠标左键,并向左/右拖动,可以改变窗口的布局'
of_reset_tip()
end subroutine
public subroutine of_setupdown (readonly graphicobject ago_u, readonly graphicobject ago_d, integer ai);
//====================================================================
// ai 位置基准
//====================================================================
//if isvalid(iuo_1) then return
iuo_1 = ago_u
iuo_2 = ago_d
ib_vertical = false
of_resize(ai )
this.tag = '在这里按住鼠标左键,并向上/下拖动,可以改变窗口的布局'
of_reset_tip()
end subroutine
event constructor;call super::constructor;//ib_live = this.enabled
this.enabled = true
of_setpointer()
end event
on lht_vo_splitter.create
call super::create
end on
on lht_vo_splitter.destroy
call super::destroy
end on
event doubleclicked;if not ib_live then
this.backcolor = f_invert_color(this.backcolor)
end if
end event
event rbuttondown;////恢复
//mousedown = false
//ReleaseCapture()
//if not ib_live then
//this.backcolor = f_invert_color(this.backcolor)
//end if
end event
event ue_win_mousemove;call super::ue_win_mousemove;if not mousedown then
//if (XPos < 0 or YPos< 0 ) or (XPos > this.Width or YPos > this.Height) then
//ReleaseCapture()
//this.border = false
//elseif global_api.GetCapture()<>handle(this) THEN
//SetCapture(handle(this))
//this.borderstyle = StyleRaised!
//this.border = true
//end if
return
end if
long nx,ny,tx,ty
nx = unitstopixels( this.x, xunitstopixels! )
ny = unitstopixels( this.y, yunitstopixels! )
if ib_vertical then
nx += unitstopixels( xpos, xunitstopixels! ) - oldxpos
tx = unitstopixels( iuo_1.x, xunitstopixels! ) + il_distance
if nx < tx then nx = tx
tx = unitstopixels( iuo_2.x, xunitstopixels! ) + &
unitstopixels( iuo_2.width, xunitstopixels! )- &
unitstopixels( this.width, xunitstopixels! ) - il_distance
if nx > tx then nx = tx
else
ny += unitstopixels( ypos, yunitstopixels! ) - oldypos
ty = unitstopixels( iuo_1.y, yunitstopixels! ) + il_distance
if ny < ty then ny = ty
ty = unitstopixels( iuo_2.y, yunitstopixels! ) + &
unitstopixels( iuo_2.height, yunitstopixels! ) - &
unitstopixels( this.height, yunitstopixels! ) - il_distance
if ny > ty then ny = ty
end if
tx = pixelstounits( nx - unitstopixels( this.x, xunitstopixels! ), xpixelstounits! )
ty = pixelstounits( ny - unitstopixels( this.y, yunitstopixels! ), ypixelstounits! )
if tx = 0 and ty = 0 then return
if not ib_live then
this.move( pixelstounits( nx, xpixelstounits! ), pixelstounits( ny, ypixelstounits! ) )
this.setredraw(true)
return
end if
if ib_vertical then
iuo_1.width = iuo_1.width + tx
iuo_2.setredraw( false )
iuo_2.width = iuo_2.width - tx
iuo_2.x = iuo_2.x + tx
else
iuo_1.height = iuo_1.height + ty
iuo_2.setredraw( false )
iuo_2.height = iuo_2.height - ty
iuo_2.y = iuo_2.y + ty
end if
iuo_2.setredraw(true)
tx = this.x
ty = this.y
this.move( pixelstounits( nx, xpixelstounits! ), pixelstounits( ny, ypixelstounits! ) )
this.event ue_drag( tx, ty )
end event