求助大神,BCB中能不能自己建一个ScrollBar控制StringGrid的滑动呢?
要实现的功能是随着滑块下滑能显示滑到了第几行,但是StringGrid自带的滚动条好像不能实现,求助大佬
程序代码:
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" THintWindow *fmHint = NULL; TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Application->CreateForm(HintWindowClass,&fmHint); // 建立fmHint实例 } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { for(int Col=0; Col<StringGrid1->ColCount; Col++) StringGrid1->Cols[Col]->Clear(); //清空 StringGrid1->RowCount = 100; StringGrid1->ColCount = 5; for(int Row=0; Row<StringGrid1->RowCount; Row++) for(int Col=0; Col<StringGrid1->ColCount; Col++) { if(!Col && Row) StringGrid1->Cells[Col][Row] = Row; else StringGrid1->Cells[Col][Row] = "示例"; } } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1TopLeftChanged(TObject *Sender) { Edit1->Text = StringGrid1->TopRow; TRect R = fmHint->CalcHintRect(100,StringGrid1->TopRow,NULL); TPoint p = Mouse->CursorPos; OffsetRect(R,p.x-15,p.y-15); fmHint->ActivateHint(R,StringGrid1->TopRow); } //---------------------------------------------------------------------------