如何制作图文并茂的按钮?

sengg 2002-08-28 02:54:07
做了一个软件,想美化一下界面!
给个程序参考一下!
...全文
87 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
xing_xing 2002-08-30
  • 打赏
  • 举报
回复
在流芳的网站上有例子,不要钱的:)
HDWH 2002-08-30
  • 打赏
  • 举报
回复
应该资源共享
jzhaohua 2002-08-30
  • 打赏
  • 举报
回复
www.pdriver.com 的销售区有 demo 下载
60 元RMB, 漂亮按钮
killerdanny 2002-08-30
  • 打赏
  • 举报
回复
WWW.LIULEE.NET
jbg 2002-08-30
  • 打赏
  • 举报
回复
结贴
HDWH 2002-08-29
  • 打赏
  • 举报
回复
给你一段代码,应该可以解决你的问题
---- 一、实现功能

---- 按钮可以显示四种状态图形:

---- 1、Normal状态;

---- 2、Disabled状态;

---- 3、MouseOver状态(鼠标进入按钮区);

---- 4、ClickDown状态(鼠标按下)。

---- 二、关键方法

---- 1、当鼠标进入按钮区域时,控件图片改换成MouseOver状态的图片,并设置状态信号;

---- 2、鼠标滑入按钮区域后用Windows API函数SetCapture来捕获鼠标输入消息,跟踪鼠标位置;

---- 3、当监测到鼠标滑出按钮区域时,用ReleaseCapture函数释放鼠标捕获,恢复按钮图片到Normal状态并设置状态信号;

---- 4、改变控件的图片(PictureName)前,先用ReleaseCapture释放鼠标捕获,然后改变PictureName属性值,接着重新调用SetCapture函数,因为改变图片后PowerBuilder重新建立了控件窗口,窗口的句柄(hWnd)也随之改变了。

---- 三、设计过程

---- 1、新建“User Object” -〉选择Visual的Standard类 -〉选择“Picture”;

---- 2、定义全局的或局部的外部函数:

// *******************************
// Declare External Functions
// *******************************
function ulong SetCapture
(ulong hwnd) library "user32.dll"
function boolean ReleaseCapture () library "user32.dll"
function boolean DrawEdge(ulong hdc,
ref rect qrc, uint edge, uint grfFlags)
library "user32.dll"

---- 3、定义结构数据类型
RECT
{
long left
long top
long right
long bottom
}

---- 4、定义控件共享变量:
// *******************************
// Declare Shared Variables
// *******************************
boolean sb_SuppressHoverBorder

---- 5、定义控件实例变量:
// *******************************
// Declare Instance Variables
// *******************************
Private:
boolean ib_MouseCaptured

Public:
string is_PicNormal
string is_PicDisabled
string is_PicMouseOver
string is_PicClickDown
int in_State

---- 6、定义用户事件:
// *******************************
// Declare User Events
// *******************************
Event Name="mousemove", ID="pbm_mousemove"
Event Name="lbuttondown", ID="pbm_lbuttondown"
Event Name="lbuttonup", ID="pbm_lbuttonup"

---- 7、编写事件代码:
// “Constructor” 事件代码
// *** begin constructor event ***
//
is_PicNormal = this.PictureName
is_PicDisabled = "Disabled状态图片.bmp"
is_PicMouseOver = "MouseOver状态图片.bmp"
is_PicClickDown = "ClickDown状态图片.bmp"
in_State = 0

sb_SuppressHoverBorder = FALSE
//
// *** end constructor event ***

// “MouseMove” 事件代码
// *** begin mousemove event ***
//
rect lr_Border

if not ib_MouseCaptured then
if flags < > 1 then
this.PictureName = is_PicMouseOver
else
// Left Button Down
this.PictureName = is_PicClickDown
end if
in_State = 1

SetCapture(handle(this))
ib_MouseCaptured = TRUE

if not sb_SuppressHoverBorder then
lr_Border.left = 0
lr_Border.top = 0
lr_Border.right = UnitsToPixels
(this.Width, XUnitsToPixels!)
lr_Border.bottom = UnitsToPixels
(this.Height, YUnitsToPixels!)

if flags < > 1 then
DrawEdge(GetDC(handle(this)),
lr_Border, 4, 1+2+4+8)
else
// Left Button Down
DrawEdge(GetDC(handle(this)),
lr_Border, 2, 1+2+4+8)
end if

end if

else

// 检测鼠标是否滑出按钮区域?
if (XPos < 0 or YPos < 0) or (XPos >
this.Width or YPos > this.Height) then
ib_MouseCaptured = FALSE
ReleaseCapture()

in_State = 0
this.PictureName = is_PicNormal

end if

end if

return 1
//
// *** end mousemove event ***

// “LButtonDown” 事件代码
// *** begin lbuttondown event ***
//
rect lr_Border

if ib_MouseCaptured then
ib_MouseCaptured = FALSE
ReleaseCapture()
end if

in_State = 2
this.PictureName = is_PicClickDown

SetCapture(handle(this))
ib_MouseCaptured = TRUE

if not sb_SuppressHoverBorder then
lr_Border.left = 0
lr_Border.top = 0
lr_Border.right = UnitsToPixels
(this.Width, XUnitsToPixels!)
lr_Border.bottom = UnitsToPixels
(this.Height, YUnitsToPixels!)

DrawEdge(GetDC(handle(this)),
lr_Border, 2, 1+2+4+8)
end if

return 1
//
// *** end lbuttondown event ***

// “LButtonUp” 事件代码
// *** begin lbuttonup event ***
//
rect lr_Border

if ib_MouseCaptured then
ib_MouseCaptured = FALSE
ReleaseCapture()
end if

if (XPos < 0 or YPos < 0) or (XPos >
this.Width or YPos > this.Height) then
in_State = 0
this.PictureName = is_PicNormal

else
in_State = 1
this.PictureName = is_PicHover

SetCapture(handle(this))
ib_MouseCaptured = TRUE

if not sb_SuppressHoverBorder then
lr_Border.left = 0
lr_Border.top = 0
lr_Border.right = UnitsToPixels
(this.Width, XUnitsToPixels!)
lr_Border.bottom = UnitsToPixels
(this.Height, YUnitsToPixels!)
DrawEdge(GetDC(handle(this)),
lr_Border, 4, 1+2+4+8)
end if

end if

// 产生Clicked事件
this.event post clicked()
return 1

//
// *** end lbuttonup event ***

// “Other” 事件代码
// *** begin other event ***
//
if message.number = 533 and ib_MouseCaptured then
// wm_CaptureChanged
ib_MouseCaptured = FALSE
in_State = 0
this.PictureName = is_PicNormal
return 1
end if

return 0
//
// *** end other event ***

----  四、简要说明
---- 1、ib_MouseCaptured变量是作为MouseMove事件的刷新控件图片的信号灯及判断是否已安装了鼠标捕捉器;

---- 2、sb_SuppressHoverBorder变量,默认值为FALSE,当值为TRUE时,控件不绘制凸或凹边框;

---- 3、“Other”事件,当鼠标捕捉器被释放或被替换时会触发WM_CAPTURECHANGED事件,例如:您在Clicked事件中调用MessageBox函数时,将触发WM_CAPTURECHANGED事件,在此事件代码中恢复按钮到Normal状态。


-----------------------------------------------
希望对你有所帮助
jbg 2002-08-29
  • 打赏
  • 举报
回复
又发了一个带应用的,这回别告诉我打不开了。
fing 2002-08-29
  • 打赏
  • 举报
回复
值得学习啊
balloonman2002 2002-08-28
  • 打赏
  • 举报
回复
回复人: sengg(一个萝卜一个坑) ( ) 信誉:94 2002-08-28 17:37:00 得分:0


怎么打开啊?我用库文件管理打开不了,老是说Please choose an application library。这是怎么回事?


你要打开PBL的话,要先把这个PBL在APPLICATION属性中的LIBRARY中BROWSE进去的!
wallis 2002-08-28
  • 打赏
  • 举报
回复
用DW
balloonman2002 2002-08-28
  • 打赏
  • 举报
回复
而且这样LABEL可以随便放到PICTUREBOX的四周啊,想放哪放哪,多好,:)
balloonman2002 2002-08-28
  • 打赏
  • 举报
回复
sengg(一个萝卜一个坑) ( ) 信誉:94 2002-08-28 16:53:00 得分:0

我是说图形和文字分开
比如按钮上一个简单的图形旁边在一两个文字
而Picturebutton是文字写在图形上面

这样更简单了,你弄一个PICTUREBOX,然后旁边放一个LABEL,有何不妥?


sengg 2002-08-28
  • 打赏
  • 举报
回复
怎么打开啊?我用库文件管理打开不了,老是说Please choose an application library。这是怎么回事?
jbg 2002-08-28
  • 打赏
  • 举报
回复
邮件已发,请查收。
sengg 2002-08-28
  • 打赏
  • 举报
回复
我是说图形和文字分开
比如按钮上一个简单的图形旁边在一两个文字
而Picturebutton是文字写在图形上面
sengg 2002-08-28
  • 打赏
  • 举报
回复
地址dsj9999@sina.com
jbg 2002-08-28
  • 打赏
  • 举报
回复
告诉我地址,发给你一份
zyqherozyqhero 2002-08-28
  • 打赏
  • 举报
回复
可以添加图片菜单。致于图片可以自己制作或下载。如果想让图片活动可以用PHOTOSHOP或FIREWORKS制作一个GIF图片
balloonman2002 2002-08-28
  • 打赏
  • 举报
回复
PICTUREBUTTON就图文并茂;
sengg 2002-08-28
  • 打赏
  • 举报
回复
to:hzhxxx
能不能发给我参考一下,谢谢
dsj9999@sina.com
加载更多回复(5)

1,108

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧