|
답변 준비 중에 미리 올리신 분이 계시네요. 대동소이합니다. 참고하세요.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int MouseCol, MouseRow, PreCol, PreRow; // <== 변수 선언.
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
PreCol = 1;
PreRow = 1;
for(int i=0; i<StringGrid1->RowCount; i++){
for(int j=0; j<StringGrid1->ColCount; j++) {
StringGrid1->Cells[i][j] = IntToStr(i+1) + ":" + IntToStr(j+1);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if (ACol == MouseCol && ARow == MouseRow){
StringGrid1->Canvas->Brush->Color = clRed;
StringGrid1->Canvas->FillRect(Rect);
StringGrid1->Canvas->TextOut(Rect.Left+20,Rect.Top+2,StringGrid1->Cells[ACol][ARow]);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
TGridCoord gc = StringGrid1->MouseCoord(X,Y);
MouseCol = gc.X;
MouseRow = gc.Y;
if(MouseCol < 1 || MouseRow <1) return;
if(MouseCol != PreCol || MouseRow != PreRow){
StringGrid1->Col = MouseCol;
StringGrid1->Row = MouseRow;
SendMessage(StringGrid1->Handle, WM_LBUTTONDOWN, 0,0);
SendMessage(StringGrid1->Handle, WM_LBUTTONUP, 0,0);
PreCol = MouseCol;
PreRow = MouseRow;
}
}
//---------------------------------------------------------------------------
turker 님이 쓰신 글 :
: 안녕하세요... stringgrid에 대한 질문인데요...
: 검색해도 마우스에 따른 cell색깔 바꾸기는 없는 것 같더라구요..
: string grid에서 마우스가 올라가 있는 cell만 색깔을 바꾸려면 어떻게 해야 할까요...
:
: 모든 cell은 흰 색이고 마우스가 올라가 있는 cell만 빨강, 또 벗어나면 다시 원래대로 흰 색...이런 식으로 하려면 어떻게 해야 하는 지 좀 알려주세요...
:
: ondrawcell에서 마우스가 올라가있는 것을 인식할 수 있는 방법이 있을까요?
|