社区
VCL组件使用和开发
帖子详情
在xp下speedbutton的背景色问题
yangzhenhai
2003-05-21 11:02:22
我在winxp下运行,发现speedbutton的down属性设了true以后,背景色变成了白色。
但是我希望它的背景色是灰的,怎么设。
我修改了speedbutton的winproc事件,当重画时,修改背景色为灰,但是不行。
如果down属性设为false,又可以。
请问是怎么回事?
...全文
178
13
打赏
收藏
在xp下speedbutton的背景色问题
我在winxp下运行,发现speedbutton的down属性设了true以后,背景色变成了白色。 但是我希望它的背景色是灰的,怎么设。 我修改了speedbutton的winproc事件,当重画时,修改背景色为灰,但是不行。 如果down属性设为false,又可以。 请问是怎么回事?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
13 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yangzhenhai
2003-05-21
打赏
举报
回复
我的背景色明明色灰色,speedbutton怎么变成白色了
yangzhenhai
2003-05-21
打赏
举报
回复
怎么不让他变
duduwolf
2003-05-21
打赏
举报
回复
当down=true时,speedbutton的背景色就自动变为他的parent的颜色了
yangzhenhai
2003-05-21
打赏
举报
回复
up
jishiping
2003-05-21
打赏
举报
回复
多看看源程序。我就是看(调试)源程序,才知道如何解决的。
yangzhenhai
2003-05-21
打赏
举报
回复
恩!终于解决了,你是怎么搞定的?去哪可以找到这方面的资料?
我的email yangzhenhai000@163.com
初学bcb问题多多,到时候还得向你多请教!
jishiping
2003-05-21
打赏
举报
回复
刚刚试了一下,看了一下效果和源程序,这样改写:
void __fastcall TMySpeedButton::WndProc(TMessage& Msg)
{
TRect Rect;
TControlCanvas* Canvas;
Graphics::TBitmap* Bmp;
TControl::WndProc(Msg);
if (Msg.Msg!=WM_PAINT) return;
Canvas = new TControlCanvas;
Canvas->Control = this;
Bmp = new Graphics::TBitmap;
Rect = this->ClientRect;
Bmp->Width = Rect.Width();
Bmp->Height = Rect.Height();
Bmp->Canvas->CopyRect(Rect,
Canvas, Rect);
Bmp->Transparent = true;
for(int n=0; n<2; n++) {
if (n==1 && !Btn->Down) break;
//对于Down的情形,需要做2次处理
Bmp->TransparentColor = n==1 ?
clBtnHighlight : clBtnFace;
Canvas->Brush->Color = FColor;
Canvas->FillRect(Rect);
Canvas->Draw(Rect.left, Rect.top, Bmp);
}
delete Bmp; delete Canvas;
}
「已注销」
2003-05-21
打赏
举报
回复
up
yangzhenhai
2003-05-21
打赏
举报
回复
就是抄你上次的代码。除了down这种情况,其它都挺好的。
yangzhenhai
2003-05-21
打赏
举报
回复
我做的一个组件,myspeedbutton,我定义了一个color属性,就当是背景色了
这是第一个文件myspeedbutton.h
//---------------------------------------------------------------------------
#ifndef MySpeedButtonH
#define MySpeedButtonH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Buttons.hpp>
#include <Controls.hpp>
class PACKAGE TMySpeedButton : public TSpeedButton
{
private:
Graphics::TColor FColor;
void __fastcall DrawItem(Graphics::TColor Value);
protected:
void __fastcall WndProc(TMessage& Msg);
public:
void __fastcall SetColor(Graphics::TColor Value);
__fastcall TMySpeedButton(TComponent* Owner);
__published:
__property Graphics::TColor Color = {read=FColor, write=SetColor, stored=IsColorStored, default=12632256};
};
//---------------------------------------------------------------------------
这是第二个文件myspeedbutton.cpp
#include <vcl.h>
#pragma hdrstop
#include "MySpeedButton.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TMySpeedButton *)
{
new TMySpeedButton(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMySpeedButton::TMySpeedButton(TComponent* Owner)
: TSpeedButton(Owner)
{
}
void __fastcall TMySpeedButton::SetColor(Graphics::TColor Value) {
FColor = Value;
this->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TMySpeedButton::WndProc(TMessage& Msg)
{
TRect Rect;
TControlCanvas* Canvas;
Graphics::TBitmap* Bmp;
TControl::WndProc(Msg);
if (Msg.Msg!=WM_PAINT) return;
Canvas = new TControlCanvas;
Canvas->Control = this;
Bmp = new Graphics::TBitmap;
Rect = this->ClientRect;
Bmp->Width = Rect.Width();
Bmp->Height = Rect.Height();
Bmp->Canvas->CopyRect(Rect,
Canvas, Rect);
Bmp->Transparent = true;
Bmp->TransparentColor = clBtnFace;
Canvas->Brush->Color = FColor;
Canvas->FillRect(Rect);
Canvas->Draw(Rect.left, Rect.top, Bmp);
delete Bmp;
delete Canvas;
}
//---------------------------------------------------------------------------
namespace Myspeedbutton
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMySpeedButton)};
RegisterComponents("Mybtn", classes, 0);
}
}
//---------------------------------------------------------------------------
jishiping
2003-05-21
打赏
举报
回复
肯定是你写错了,将你的代码贴出来。
yangzhenhai
2003-05-21
打赏
举报
回复
to jsp:
我就是用你上面的这个办法。不过我是重载了speedbutton控件的winproc方法做的。一切都很好。
不过就是按了down以后,就控制不了了。用了那个方法,也还是改变不了颜色,他总是白的。
因为我文本的颜色规定是白的,所以就看不清button上的字了。
非常着急,我看到有人做过的,可以让speedbutton按下去以后,底色也是灰的。应该是可以实现的,就是不知道他是怎么做的。
jishiping
2003-05-21
打赏
举报
回复
这是VCL故意将颜色设成不一样,让用户可以一下子就能看出按钮被按下去了,我觉得这
没有什么不好。如果你认为这样不好的话,可以参看我之前解答的一个帖子:
http://expert.csdn.net/Expert/TopicView1.asp?id=1796055
这个帖子里,是针对Form上有多个按钮写的,如果只有一个按钮,代码还可以简化。
delphi控件使用
Standard页 1- Tlistbox控件 重要属性items.* 举例,界面设计如下左,执行结果如下右: 代码为 procedure TForm1.
Button
1Click(Sender: TObject); begin edit1.Text := listbox1.Items.CommaText; edit2.Text := listbox1.Items.Text;...
制作从屏幕右下角逐渐弹出的消息提示框
制作从屏幕右下角逐渐弹出的消息提示框 微软的每一个产品,无论功能还是界面设计都会带给我们一定的惊喜,比如Office
XP
、Office2003、Messenger的界面设计,早已成为众多软件竞相模仿的对象,就拿Messenger来说,我就见过好几套网络视频会议的软件都借鉴了它的界面风格。 前段时间因为要在原来的软件上增加一个快捷键提示窗体,这个提示窗要求在显...
常用DELPHI控件属性事件设置说明(第二篇)
常用DELPHI控件属性事件设置说明(第二篇) (2012-03-13 08:48:48) 转载▼ 标签: delphi控件属性 it 分类: delphi 常用DELPHI控件属性设置说明 目录 TForm Class TPanel组件 TToolBar Class TTool
Button
C
Delphi 右下角弹出提示框
2019独角兽企业重金招聘Python工程师标准>>> ...
制作像MSN、QQ那样的消息提示框
微软的每一个产品,无论功能还是界面设计都会带给我们一定的惊喜,比如Office
XP
、Office2003、Messenger的界面设计,早已成为众多软件竞相模仿的对象,就拿Messenger来说,我就见过好几套网络视频会议的软件都借鉴了它的界面风格。 前段时间因为要在原来的软件上增加一个快捷键提示窗体,这个提示窗要求在显示的时候比较醒目美观能引起用户注意,显示后不影响用户操作,能够关掉。很自
VCL组件使用和开发
604
社区成员
13,456
社区内容
发帖
与我相关
我的任务
VCL组件使用和开发
C++ Builder VCL组件使用和开发
复制链接
扫一扫
分享
社区描述
C++ Builder VCL组件使用和开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章