change the color of a disabled TEdit?
change the color of a disabled TEdit?
Author: P. Below
Category: VCL
{Question:
How can I change the color of a disabled (Edit1.Enabled := false;) control?
I do not want the normal grey color.
Answer:
Two options:
1) place the control on a panel and disable the panel instead of the control.
This way the color stays to whatever you set it.
2) make a descendent and take over the painting when it is disabled.
Here is an example:}
unit PBExEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TPBExEdit = class(TEdit)
private
{ Private declarations }
FDisabledColor: TColor;
FDisabledTextColor: TColor;
procedure WMPaint(var msg: TWMPaint); message WM_PAINT;
procedure WMEraseBkGnd(var msg: TWMEraseBkGnd); message WM_ERASEBKGND;
procedure SetDisabledColor(const Value: TColor); virtual;
procedure SetDisabledTextColor(const Value: TColor); virtual;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(aOwner: TComponent); override;
published
{ Published declarations }
property DisabledTextColor: TColor read FDisabledTextColor
write SetDisabledTextColor default clGrayText;
property DisabledColor: TColor read FDisabledColor
write SetDisabledColor default clWindow;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PBGoodies', [TPBExEdit]);
end;
constructor TPBExEdit.Create(aOwner: TComponent);
begin
inherited;
FDisabledColor := clWindow;
FDisabledTextColor := clGrayText;
end;
procedure TPBExEdit.SetDisabledColor(const Value: TColor);
begin
if FDisabledColor <> Value then
begin
FDisabledColor := Value;
if not Enabled then
Invalidate;
end;
end;
procedure TPBExEdit.SetDisabledTextColor(const Value: TColor);
begin
if FDisabledTextColor <> Value then
begin
FDisabledTextColor := Value;
if not Enabled then
Invalidate;
end;
end;
procedure TPBExEdit.WMEraseBkGnd(var msg: TWMEraseBkGnd);
var
Canvas: TCanvas;
begin
if Enabled then
inherited
else
begin
Canvas:= TCanvas.Create;
try
Canvas.Handle := msg.DC;
SaveDC(msg.DC);
try
canvas.Brush.Color := FDisabledColor;
canvas.Brush.Style := bsSolid;
canvas.Fillrect(clientrect);
msg.Result := 1;
finally
RestoreDC(msg.DC, - 1);
end;
finally
canvas.free
end;
end;
end;
procedure TPBExEdit.WMPaint(var msg: TWMPaint);
var
Canvas: TCanvas;
ps: TPaintStruct;
CallEndPaint: Boolean;
begin
if Enabled then
inherited
else
begin
CallEndPaint := False;
Canvas:= TCanvas.Create;
try
if msg.DC <> 0 then
begin
Canvas.Handle := msg.DC;
ps.fErase := true;
end
else
begin
BeginPaint(Handle, ps);
CallEndPaint:= True;
Canvas.handle := ps.hdc;
end;
if ps.fErase then
Perform(WM_ERASEBKGND, Canvas.Handle, 0);
SaveDC(canvas.handle);
try
Canvas.Brush.Style := bsClear;
Canvas.Font := Font;
Canvas.Font.Color := FDisabledTextColor;
Canvas.TextOut(1, 1, Text);
finally
RestoreDC(Canvas.Handle, - 1);
end;
finally
if CallEndPaint then
EndPaint(handle, ps);
Canvas.Free
end;
end;
end;
end.
change the color of a disabled TEdit?的更多相关文章
- javafx ComboBox Event and change cell color
public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...
- highcharts dynamic change line color
mouseOut: function(){ this.series.graph.attr({"stroke","#ccc"}) }
- ImportError: No module named _curses;Color support is disabled, python-curses is not installed.解决办法
linux系统默认安装了python2.6, 但是发现python2.7 import curses时 提示 找不到_curses 错误. 用pip(python2.7 )安装了curses-204 ...
- Change the color of a link in an NSMutableAttributedString
Swift Updated for Swift 3 Use with a textView.linkTextAttributes = [NSForegroundColorAttributeName: ...
- mplayer-for-windows change color scheme in win 7
Q: When I play movie on Windows7, always comes this message: The color scheme has been changed The f ...
- How to change the text color in the terminal
You can open the file ~/.bashrc and then choose the force_color_prompt=yes otherwise, you can change ...
- Chrome DevTools: Color tricks in the Elements Panel
shift + click to change the color format Tip one The Colour Platters are customeised for you .they s ...
- Entity Framework Code First - Change Tracking
In this post we will be discussing about change tracking feature of Entity Framework Code First. Cha ...
- 快速 图片颜色转换迁移 Color Transfer Opencv + Python
Super fast color transfer between images About a month ago, I spent a morning down at the beach, w ...
随机推荐
- Control.DataBinding数据绑定细解
在C#操作数据库过程中,针对一般的文本控件,比如TextBox,Label等,我们赋值直接使用类似TextBox.Text=****的方式 来进行,这种方式从某种意义上来说的确是最简便的方式,但是对于 ...
- Java中模拟POST上传文件
/** * * @param url 请求URL * @param filePath 本地文件地址 * @return */ public static String upload(String ur ...
- hive 字符集问题 报错 Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:For direct MetaStore DB connections,
学习hive 使用mysql作为元数据 hive创建数据库和切换数据库都是可以的 但是创建表就是出问题 百度之后发现 是编码问题 特别记录一下~~~ 1.报错前如图: 2.在mysql数据库中执行如 ...
- 使用Navicat连接阿里云服务器上的MySQL数据库
1.首先打开Navicat,文件>新建连接> 2,两张连接方法 1>常规中输入数据库的主机名,端口,用户名,密码 这种直接连就可以了 第2种方法: 常规中输入数据库的信息,主机名用l ...
- 14 javaBean 组件
bean类不应该有公开的实例变量. 持续性的值应该通过 getXxx 和 setXxx 方法访问. <jsp: useBean id=”beanName” class=”package.Clas ...
- 简要描述如何结合struts、hibernate、spring开发Web应用?
简要描述如何结合struts.hibernate.spring开发Web应用? 解答:Struts可以将jsp页面的表单关联起来,就是把JSP页面的表单数据封装成javaBean,这样的话,在acti ...
- 详略。。设计模式2——单例变形(多例).。。。studying
★ 缓存在单例中的使用("单例+缓存"技术) 缓存在编程中使用非常频繁,有着非常关键的数据,它可以帮助程序实现以空间换取时间, 通常被设计成整个应用程序所共享的一个空间,现要求实现 ...
- 分享一个Unity3D小作品,源码地址已公布在文章开头!
Update:回复量有点大,楼主工作期间可能无暇向童鞋们发送源码,为了不让童鞋们久等,现公布源码地址. 链接: http://pan.baidu.com/s/1sjpYW4d 密码: zhp9 请注 ...
- Python捕获异常
一.常见异常 1.语法错误:SyntaxError:invalid syntax (1)案例: (1)解决方法: ①查看代码有没有红色波浪线 ②熟悉python基本语法 2.变量名不存在:NameEr ...
- web前端入坑第五篇:秒懂Vuejs、Angular、React原理和前端发展历史
秒懂Vuejs.Angular.React原理和前端发展历史 2017-04-07 小北哥哥 前端你别闹 今天来说说 "前端发展历史和框架" 「前端程序发展的历史」 「 不学自知, ...