線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1041
推到 Plurk!
推到 Facebook!

StringGrid

尚未結案
jason_cyl329
高階會員


發表:123
回覆:155
積分:105
註冊:2003-05-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-09-09 13:52:51 IP:211.23.xxx.xxx 未訂閱
請問, 使用TStringGrid,假設有很多的格子,游標還在最上端,使用ScrollBar拉到最底端,這時在用滾輪往下移動,畫面又會由原來的游標處開始往下移動,請問要如何防止這種狀況?我需要的是已經到最下端,就應該以此位址開始來做移動的變化!!
m8815010
版主


發表:99
回覆:372
積分:289
註冊:2003-11-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-09-10 12:02:06 IP:61.63.xxx.xxx 未訂閱
引言: 請問, 使用TStringGrid,假設有很多的格子,游標還在最上端,使用ScrollBar拉到最底端,這時在用滾輪往下移動,畫面又會由原來的游標處開始往下移動,請問要如何防止這種狀況?我需要的是已經到最下端,就應該以此位址開始來做移動的變化!!
jason_cyl329你好: 嗯,其實之前我用了幾次 >! 觀察一下,這種狀況應該是元件本身 >: < class="code"> In Unit1.h ~~ class TForm1 : public TForm { __published: // IDE-managed Components TStringGrid *StringGrid1; void __fastcall FormCreate(TObject *Sender); private: // User declarations TWndMethod OldStringGridWndProc; //add this line void __fastcall StringGridWndProc(TMessage& Message); //add this line public: // User declarations __fastcall TForm1(TComponent* Owner); }; ~~

In Unit1.cpp
~~
TForm1 *Form1;
int i=0;    //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
 OldStringGridWndProc=StringGrid1->WindowProc;
 StringGrid1->WindowProc=StringGridWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 StringGrid1->RowCount=50;
 StringGrid1->ColCount=15;     for (int i=0;i<15;i  ) {
      for (int j=0;j<50;j  )
           StringGrid1->Cells[i][j]="(" IntToStr(i) "," IntToStr(j) ")";
 }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGridWndProc(TMessage& Message)
{
 if (Message.Msg==WM_VSCROLL) {
     if (LOWORD(Message.WParam)==SB_ENDSCROLL) {
         i  ;
         this->Caption=i;             TGridRect myRect;
         myRect.Left   = 1;
         myRect.Top    = StringGrid1->TopRow;
         myRect.Right  = 1;
         myRect.Bottom = StringGrid1->TopRow;
         StringGrid1->Selection = myRect;
         //StringGrid1->SetFocus();
     }
 }     OldStringGridWndProc(Message);
}
精神就是每次使用Scroo bar操作完後,自動將focus的cell設在本頁的最上最左一格cell,這樣就比較有同步的感覺了< >! 注意: >! 以上,參著參著< >!
jason_cyl329
高階會員


發表:123
回覆:155
積分:105
註冊:2003-05-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-09-10 12:59:09 IP:211.23.xxx.xxx 未訂閱
感謝m8815010兄的指教, 以後有問題還得敬請指教!!
系統時間:2024-05-06 5:23:37
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!