GIF:
1、引用API是为了画4个角的弧度;
FUNCTION ulong CreateRoundRectRgn(ulong X1,ulong Y1,ulong X2,ulong Y2,ulong X3,ulong Y3) LIBRARY "gdi32.dll"
FUNCTION ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY "user32.dll"
2、PB9代码,创建Custom Visual可视化对象,命名为vo_commanbutton
forward
global type vo_commanbutton from userobject
end type
type st_text from statictext within vo_commanbutton
end type
end forward
global type vo_commanbutton from userobject
integer width = 453
integer height = 106
long backcolor = 67108864
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
event ue_lbuttondown pbm_lbuttondown
event dd pbm_bndoubleclicked
event ue_lbuttondblclk pbm_lbuttondblclk
event clicked pbm_lbuttonup
st_text st_text
end type
global vo_commanbutton vo_commanbutton
type prototypes
FUNCTION ulong CreateRoundRectRgn(ulong X1,ulong Y1,ulong X2,ulong Y2,ulong X3,ulong Y3) LIBRARY "gdi32.dll"
FUNCTION ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY "user32.dll"
end prototypes
type variables
CONSTANT long il_number= 5.7
boolean ib_bold = false //400|加粗700
boolean ib_underline = false //下划线
boolean ib_strkeout = false //删除线
int ii_fontsize=18
string is_text = '测试按钮'
long il_ClickedColor = 14589000,il_color = 14120960//il_HoveColor = 14727818,
long il_FontColor = 16777215
long il_radian = 5
end variables
forward prototypes
public subroutine of_draw (integer as_choose)
end prototypes
event ue_lbuttondown;//
of_draw(1)
end event
event ue_lbuttondblclk;of_draw(1)
end event
event clicked;of_draw(0)
end event
public subroutine of_draw (integer as_choose);string ls_err,ls_syntax
long ll_width,ll_height
long ll_y = 0,ll_x = 0
ll_width = this.width
ll_height = il_number * ii_fontsize
ll_y = (10+this.height - ll_height) / 2
choose case as_choose
case 0
this.backcolor = il_color
st_text.backcolor = il_color
case 1
ll_x = 5
ll_y = ll_y + 5
this.backcolor = il_ClickedColor
st_text.backcolor = il_ClickedColor
case 1
end choose
st_text.x = ll_x
st_text.y=ll_y
st_text.text = is_text
st_text.textsize= -ii_fontsize
st_text.width = ll_width
st_text.height = this.height
st_text.textcolor = il_FontColor
if ib_bold then
st_text.weight = 700
else
st_text.weight = 400
end if
st_text.underline =ib_underline
st_text.italic = ib_strkeout
long ll_Rgn
//圆弧角
ll_width= UnitsToPixels(this.Width,Xunitstopixels!)
ll_height=UnitsToPixels(this.Height, Yunitstopixels!)
ll_Rgn=Createroundrectrgn(0,0,Ll_width,Ll_height,il_radian,il_radian)
Setwindowrgn(Handle(this),ll_Rgn,True)
//
end subroutine
on vo_commanbutton.create
this.st_text=create st_text
this.Control[]={this.st_text}
end on
on vo_commanbutton.destroy
destroy(this.st_text)
end on
event constructor;
of_draw(0)
end event
type st_text from statictext within vo_commanbutton
integer width = 457
integer height = 74
integer textsize = -18
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 67108864
boolean enabled = false
alignment alignment = center!
boolean focusrectangle = false
end type
4、参数说明