Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  136

•  TDictionary Custom Sort  3 318

•  Fast Watermark Sources  3 065

•  3D Designer  4 825

•  Sik Screen Capture  3 321

•  Patch Maker  3 536

•  Айболит (remote control)  3 637

•  ListBox Drag & Drop  2 996

•  Доска для игры Реверси  81 568

•  Графические эффекты  3 927

•  Рисование по маске  3 232

•  Перетаскивание изображений  2 613

•  Canvas Drawing  2 735

•  Рисование Луны  2 561

•  Поворот изображения  2 166

•  Рисование стержней  2 161

•  Paint on Shape  1 564

•  Генератор кроссвордов  2 226

•  Головоломка Paletto  1 764

•  Теорема Монжа об окружностях  2 217

•  Пазл Numbrix  1 682

•  Заборы и коммивояжеры  2 052

•  Игра HIP  1 279

•  Игра Go (Го)  1 225

•  Симулятор лифта  1 471

•  Программа укладки плитки  1 214

•  Генератор лабиринта  1 542

•  Проверка числового ввода  1 352

•  HEX View  1 490

•  Физический маятник  1 355

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Изменить цвет неактивного TEdit



Оформил: DeeCo

{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.




Похожие по теме исходники

Couleur (цветовая палитра)

Изменение цвета изображения

Расширение компонента TEdit




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте