TControl Enable=False 時, 如何設定 Font.Color 的顏色? |
尚未結案
|
Wawa
一般會員 發表:27 回覆:55 積分:16 註冊:2002-10-04 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
有一篇 Peter Below 大大的範例, 修改 TEdit Disable 後
的 Color 與 Font Color, 如下:
http://groups.google.com.tw/groups?hl=zh-TW&lr=&ie=UTF-8&oe=UTF-8&selm=VA.0000a1e2.0060cc29%40nomail.please&rnum=3
unit PBExEdit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TPBExEdit = class(Tedit) private FDisabledColor: TColor; FDisabledTextColor: TColor; { Private declarations } 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; { TPBExEdit } 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; { Else } 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; { Else } end; end.--- Everything I say is a lie. |
Wawa
一般會員 發表:27 回覆:55 積分:16 註冊:2002-10-04 發送簡訊給我 |
|
JasonSu
一般會員 發表:1 回覆:10 積分:7 註冊:2003-06-26 發送簡訊給我 |
[code delphi]
procedure EnableControl(AControl: TWinControl; Enable: Boolean); begin With AControl Do Begin If Enable Then Begin SetWindowLong(Handle, GWL_STYLE, (Not WS_DISABLED) And GetWindowLong(Handle, GWL_STYLE)); End Else Begin SetWindowLong(Handle, GWL_STYLE, WS_DISABLED GetWindowLong(Handle, GWL_STYLE)); End; End; end; [/code] 使用範例 EnableControl(Edit1, False); |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |