全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1289
推到 Plurk!
推到 Facebook!

滾輪滑鼠與二個DBGRID

尚未結案
Paicaso
中階會員


發表:140
回覆:124
積分:52
註冊:2002-09-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-11 22:01:43 IP:221.169.xxx.xxx 未訂閱
關於滾輪滑鼠與DBGRID捲動的問題 許多先進以討論許多 參考資料中用以下之方式,但資料並不會在游標所在位置 在 protect 加入 function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override; function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override; implementation : function TWDBGrid.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; begin DataSource.dataset.next; inherited DoMouseWheelDown(Shift, MousePos); refresh; end; function TWDBGrid.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; begin DataSource.dataset.Prior; inherited DoMouseWheelUp(Shift,MousePos); refresh; end; 故我用下列方式可以解決 procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); begin If WheelDelta > 0 Then DBGrid1.Datasource.DataSet.Prior; If wheelDelta < 0 Then DBGrid1.DataSource.DataSet.Next; end; 但均有此問題就是焦點不能在該DBGRID上,否則便無效了 但我碰到一問題,便是在同一個Form中有兩個DBGRID 習慣上要取用哪一個資料便會在該DBRID上點一下,並捲動滾輪 如此焦點便會落在該DBGRID上導致滾輪無法達到所需之功能 請問該問題應該如何著手 thanks
Chance36
版主


發表:31
回覆:1033
積分:792
註冊:2002-12-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-12 04:32:30 IP:203.204.xxx.xxx 未訂閱
Paicaso 你好
試試以下做法    1.建立一個新類別借以開放OnMouseWheel    type
  TMyGrid = Class(TDBGrid)
  Public
    property OnMouseWheel; // 開放事件
  End;    2.在Form1新增一個事件程序      TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    ...........
    procedure MouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  ......... 
  End;    3.事件程序內容如下
implementation    procedure TForm1.MouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
  If Sender Is TDBGrid Then Begin  // 先判斷Sender是否為TDBGrid
    If WheelDelta > 0 Then TDBGrid(Sender).Datasource.DataSet.Prior;
    If wheelDelta < 0 Then TDBGrid(Sender).DataSource.DataSet.Next;
    Handled := True;  // 一定要加這一行,底下的問題就是少這一行所致
引言: //參考資料中用以下之方式,但資料並不會在游標所在位置
End; end; 4.最後在Form1.OnCreate事件中將上的事件程序掛上DBGrid1及DBGrid2 procedure TForm1.FormCreate(Sender: TObject); begin // 將DBGrid1及DBGrid2轉型為TMyGrid才可以指定OnMouseWheel事件 TMyGrid(DBGrid1).OnMouseWheel := MouseWheel ; TMyGrid(DBGrid2).OnMouseWheel := MouseWheel ; end; 5.大功告成........... _______________________________________ <>深藍的魚,祝您好運..........連連 發表人 -
系統時間:2024-05-19 7:11:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!