2011年7月10日 星期日

Focus焦點移轉,以顏色區分目前Focus之元件

設計視窗化介面的應用程式,提供friendly的介面才能獲得好評。
Focus焦點移轉,以顏色區分目前Focus之元件… 這句話乍看之下很難理解,實作了就知道了啦!



type
  TForm1 = class(TForm)
     ......
  private
  public
    function SetFocusedControl(Control: TWinControl): Boolean;Override;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses TypInfo;

function TForm1.SetFocusedControl(Control: TWinControl): Boolean;
var
  OldControl : TWinControl;
begin
  {焦點轉移觸發事件}
  oldControl := ActiveControl;
  Result := inherited SetFocusedControl(Control);
  {還原舊的元件顏色,透過 SetOrdProp 只要該元件有Color屬性就設定顏色 }  {SetOrdProp 定義在 TypInfo 單元}
  if OldControl<>Nil then SetOrdProp (OldControl,'color',clwhite);
  {設定新焦點元件}
  if ActiveControl<>Nil then SetOrdProp (ActiveControl,'color',$0080FFFF);
end;

沒有留言:

張貼留言