C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[9727] Re:[약간다른방법] stringgrid에서 마우스 올라가있는 cell만 색깔 바꾸기...
유부남 [] 1109 읽음    2001-08-09 15:06
답변 준비 중에 미리 올리신 분이 계시네요. 대동소이합니다. 참고하세요.

//---------------------------------------------------------------------------

#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에서 마우스가 올라가있는 것을 인식할 수 있는 방법이 있을까요?

+ -

관련 글 리스트
9713 [질문] stringgrid에서 마우스 올라가있는 cell만 색깔 바꾸기... turker 860 2001/08/09
9727     Re:[약간다른방법] stringgrid에서 마우스 올라가있는 cell만 색깔 바꾸기... 유부남 1109 2001/08/09
9720     Re:[질문] stringgrid에서 마우스 올라가있는 cell만 색깔 바꾸기... 조로 1125 2001/08/09
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.