Borland
StringGrid 셀 병합 및 표시방법 세팅
leo21c
2010. 1. 22. 16:43
1. StringGrid Component Setting
- DefaultDrawing = false;
- FixedCols = 0;
- FixedRows = 0;
- LineColor = clBtnShadow; <= 고정 셀의 색을 clBtnFace 사용하기 때문에 같은 색이면 라인이 표시되지 않기 때문
2. DrawCell 이벤트 함수
void __fastcall Form::GridDrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TRect CellRect,TextRect;
TRzStringGrid* StringGrid = static_cast<TRzStringGrid*>(Sender);
TCanvas* ACanvas = StringGrid->Canvas;
ACanvas->Brush->Color = clWhite;
ACanvas->Pen->Color = clBtnShadow;
if (ACol%2) {
CellRect = StringGrid->CellRect(ACol-1,ARow);
Rect.Left = CellRect.Left;
CellRect = StringGrid->CellRect(ACol,ARow);
Rect.Right = CellRect.Right;
if (ACol%4 == 1) ACanvas->Brush->Color = clBtnFace;
ACanvas->FillRect(Rect);
//이곳은 덱스트작업 영역
TextRect = Rect;
TextRect.Left = TextRect.Left + 10;
AnsiString CellText = "Test";
DrawText( ACanvas->Handle, CellText.c_str(), CellText.Length(), &TextRect,
DT_LEFT | DT_VCENTER | DT_SINGLELINE );
}
}
|
3. 처리 후 결과 이미지
위쪽은 변경한 상태이과 아래 부분은 변경하지 않은 부분이다.
두개의 StringGrid Component를 붙여 놓은 상태에서 캡쳐를 했다.
4.DrawText( ACanvas->Handle, CellText.c_str(), CellText.Length(), &TextRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE );
- 위의 처리 내용은Rect의왼쪽 기준, Rect의 세로 중간, 하나의 라인으로 출력하라는 뜻이다. 멀티라인으로 하고 TAB 처리를 위해서는 아래와 같이 처리하면 된다.
DrawText( ACanvas->Handle, CellText.c_str(), CellText.Length(), &TextRect, DT_LEFT | DT_TOP | DT_EXPANDTABS);
LIST