注册 登录
编程论坛 C++ Builder

求助大神,BCB中能不能自己建一个ScrollBar控制StringGrid的滑动呢?

程序员不开心 发布于 2018-03-07 11:22, 3495 次点击
要实现的功能是随着滑块下滑能显示滑到了第几行,但是StringGrid自带的滚动条好像不能实现,求助大佬
2 回复
#2
Knocker2018-03-09 12:40
程序代码:
//---------------------------------------------------------------------------

#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);

}
//---------------------------------------------------------------------------
#3
Knocker2018-03-09 12:43
StringGrid Options的goThumbTracking属性设为true
1