众所周知,stringgrid没有onscrollmove事件,我想通过wm_hscroll和wm_vscroll消息来实现此功能,请提供完整正确程序代码,必将以百分相赠,谢谢

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, DBGrids, StdCtrls;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
      private
        OldWndMethod: TWndMethod;
        procedure NewWndMethod(var Message: TMessage);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      OldWndMethod := StringGrid1.WindowProc;
      StringGrid1.WindowProc := NewWndMethod;
      with StringGrid1 do
      begin
        Cells[1,0] := 'Column 1';
        Cells[2,0] := 'Column 2';
        Cells[3,0] := 'Column 3';
        Cells[4,0] := 'Column 4';
        Cells[0,1] := 'Row 1';
        Cells[1,1] := 'Object';
        Cells[2,1] := 'Pascal';
        Cells[3,1] := 'is';
        Cells[4,1] := 'excellent';
        Cells[0,2] := 'Row 2';
        Cells[1,2] := 'Delphi';
        Cells[2,2] := 'is';
        Cells[4,2] := 'RAD';
      end;
    end;procedure TForm1.NewWndMethod(var Message: TMessage);
    begin
      case Message.Msg of
        WM_HSCROLL: ShowMessage('WM_HSCROLL');   //在这里可以调用一个方法来处理该消息
        WM_VSCROLL: ShowMessage('WM_VSCROLL');
      else
        if Assigned(OldWndMethod) then OldWndMethod(Message);
      end;
    end;end.————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, DBGrids, StdCtrls;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
      private
        OldWndMethod: TWndMethod;
        procedure NewWndMethod(var Message: TMessage);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      OldWndMethod := StringGrid1.WindowProc;
      StringGrid1.WindowProc := NewWndMethod;
      with StringGrid1 do
      begin
        Cells[1,0] := 'Column 1';
        Cells[2,0] := 'Column 2';
        Cells[3,0] := 'Column 3';
        Cells[4,0] := 'Column 4';
        Cells[0,1] := 'Row 1';
        Cells[1,1] := 'Object';
        Cells[2,1] := 'Pascal';
        Cells[3,1] := 'is';
        Cells[4,1] := 'excellent';
        Cells[0,2] := 'Row 2';
        Cells[1,2] := 'Delphi';
        Cells[2,2] := 'is';
        Cells[4,2] := 'RAD';
      end;
    end;procedure TForm1.NewWndMethod(var Message: TMessage);
    begin
      case Message.Msg of
        WM_HSCROLL: ShowMessage('WM_HSCROLL');   //在这里可以调用一个方法来处理该消息
        WM_VSCROLL: ShowMessage('WM_VSCROLL');
      else
        if Assigned(OldWndMethod) then OldWndMethod(Message);
      end;
    end;end.————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————