PB 自定义按钮(不使用api重绘)

本文详细介绍使用PowerBASIC 9(PB9)创建带有圆角的自定义按钮的全过程,包括利用API绘制圆角区域、创建CustomVisual对象以及设置按钮的外观属性和事件响应。通过调整参数,可定制按钮的颜色、大小和圆角半径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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、参数说明

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值