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 ...
随机推荐
- YAML 语法小结
专门用来写配置文件的语言,非常简洁和强大,远比 JSON 格式方便. 使用缩进表示层级关系 缩进时不允许使用Tab键,只允许使用空格. 缩进的空格数目不重要,只要相同层级的元素左侧对齐即可 # 表示注 ...
- 2018 CCPC 桂林游记
TYPE: Onsite Contest NAME: 2018 - CCPC - Guilin PLAT: HUSTOJ TIME: 2018/10/28 09:00-14:00 CST LOCA: ...
- phpQuery对数据信息的采集进一步学习
前提:需要下载:phpQuery/phpQuery.php 链接:http://www.cnblogs.com/wuheng1991/p/5145398.html 1.对于规则的部分 <?php ...
- 提高php编程效率的小结
1.如果将类的方法定义为:static,它的执行效率将提升为近4倍 2.php中数组的元素调用,使用关联数组优于索引数组 3.使用each快于print. 4.尽量使用foreach()替代for() ...
- markDownPad Key
邮箱: Soar360@live.com 授权秘钥: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImDHzWdD6xhMNLGVpbP2M5SN6b ...
- 【Raspberry Pi】GPIO-发光二极管控制
注意事项: 注意IO脚电流不能大于16mA,3V脚总电流不能大于50mA,所以两个二极管各上拉了400欧左右的电阻 采用物理针脚7和9做控制 其中output参数LOW为接通,HIGH为屏蔽 impo ...
- 修改一些IntelliJ IDEA 11的设置,使Eclipse的使用者更容易上手(转)
用惯了Eclipse,再来使用IntelliJ IDEA真是很难适应. 设置1:字体 修改IDE的字体:设置-Appearance-Look and Feel-OverRide设置你想要的字体.我设置 ...
- sql实际应用-递归查询
1.既然要谈到sql,数据库表是必须的 2.数据结构 3.获取某个节点的所有子节点 传统的写法(sql2000) 很麻烦,暂且就不写了 来看看CTE的写法 CREATE PRO ...
- 在UI线程之外,多线程处理Bitmaps
多线程处理Bitmaps 上一篇,我们讨论了:Android有效的处理Bitmap,降低内存 ,可是最好不要运行在主线程(UI线程),假设图片是本地的或者网络的又或者是其它地方的. 图片载入的 ...
- Linux下android开发环境配置
1.安装jdk 1.到sun官网下载jdk(附jdk6下载地址),根据自己的ubuntu版本选择合适的jdk版本.如你用的是ubuntu 32位系统则选择下载jdk-6u41-linux-i586.b ...