Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
請問如何在delphi中做到像vb中的lostfocus的功能!!
用下列兩列程式可以作到類似 LostFocus 的效果
(* 移往下一個 tabstop 的 WinControl 元件 *) SendMessage(Handle, wm_NextDlgCtl, 0, 0); (* 注意: 第三個引數不為零時, focus 將移往上一個控制項 *) SendMessage(Handle, wm_NextDlgCtl, 1, 0); 另外, 我剛才試作了一個 TTestEdit 元件, 增加了 LostFocus方法, 您可以參考看看: (* -------------------------------------------------- *) (* TestEdit (* ======== (* 功能概述 (* TEdit 加上 LostFocus method 的實驗性元件 (* (* 作者: wolfgang@ms2.hinet.net (* -------------------------------------------------- *) unit TestEdit; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TTestEdit = class(TEdit) (* 繼承 TEdit *) private protected public (* 建構函式 *) constructor Create(AOwner: TComponent); override; (* 解構函式 *) destructor Destroy; override; (* 增加一個 LostFocus 方法 *) procedure LostFocus; published end; procedure Register; (* 向 Delphi 註冊這個元件 *) (* -------------------------------------------------- *) implementation (* -------------------------------------------------- *) (* Register (* 向 Delphi 註冊這個元件 (* -------------------------------------------------- *) procedure Register; begin RegisterComponents('Sample', [TTestEdit]); end; (* -------------------------------------------------- *) (* 建構函式 (* -------------------------------------------------- *) constructor TTestEdit.Create(AOwner: TComponent); begin inherited Create(AOwner); (* 呼叫祖先的建構函式建構元件 *) end; { TTestEdit.Create } (* -------------------------------------------------- *) (* 解構函式 (* -------------------------------------------------- *) destructor TTestEdit.Destroy; begin inherited Destroy; (* 呼叫祖先的建構函式 *) end; { of TTestEdit.Destroy } (* -------------------------------------------------- *) (* LostFocus (* -------------------------------------------------- *) procedure TTestEdit.LostFocus; var frmCurrent: TForm; ix: integer; begin SetFocus; (* 本元件獲得鍵盤焦點 *) frmCurrent := GetParentForm(Self); (* 查出元件所屬的 Form *) (* 讓下一個 TabStop WinControl 元件獲得鍵盤焦點 *) SendMessage(frmCurrent.Handle, wm_NextDlgCtl, 0, 0); end; { TTestEdit.LostFocus } end. { of TTestEdit }
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |