Q&A

  • StringGrid에서 (OndrawCell작업) 글자가 안보여염..(ㅠㅠ)
아래와 같이 코딩을 했는데 글자가 안보이네요..

부탁드립니다.

with StringGrid1.Canvas do

begin

if (gdFixed in State) then

begin

Brush.Color := $00FF80FF;

Font.Color := clBlack;

FillRect(Rect);

end else if (StringGrid1.Cells[1,I] <> StringGrid1.Cells[7,I]) then

begin

Font.Color := clBlack;

Brush.Color := clPurple;

FillRect(Rect);

end else

begin

Font.Color := clWindowText;

Brush.Color := clWindow;

FillRect(Rect);

end;

end;



3  COMMENTS
  • Profile
    홍성락 2001.11.21 23:55
    꼴통 wrote:

    > 아래와 같이 코딩을 했는데 글자가 안보이네요..

    > 부탁드립니다.

    > with StringGrid1.Canvas do

    > begin

    > if (gdFixed in State) then

    > begin

    > Brush.Color := $00FF80FF;

    > Font.Color := clBlack;

    > FillRect(Rect);

    > end else if (StringGrid1.Cells[1,I] <> StringGrid1.Cells[7,I]) then

    > begin

    > Font.Color := clBlack;

    > Brush.Color := clPurple;

    > FillRect(Rect);

    > end else

    > begin

    > Font.Color := clWindowText;

    > Brush.Color := clWindow;

    > FillRect(Rect);

    > end;

    > end;

    //////////////////////////////////////////////////////////////////

    FillRect으로 셀을 채운후 글자는 TextRect로 다시 써야보입니다

    일단 아래것을 참고해보세요

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

    Field: TField; State: TGridDrawState);

    begin



    with TDBGrid(Sender) do begin

    if (SelectedRows.CurrentRowSelected) then begin //현선택된줄만 색칠하기

    Canvas.Brush.Color := clYellow;

    Canvas.Font.Color := clBlack;

    Canvas.FillRect(Rect);

    //필드타입에 따라 다시쓰는 위치를 조정하세요.

    if Field.DataType = ftString then

    canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, Field.AsString)

    else

    canvas.TextRect(Rect, Rect.Right - canvas.TextWidth(Field.AsString)

    - 3, Rect.Top, Field.AsString)

    end;

    end;

    end;

  • Profile
    꼴통 2001.11.22 00:47
    저렇게 코딩해서 그리드의 셀을 비교해서 특정셀만 색깔이 바꿔어야 되거든요..

    그리고 스트링 그리드의 Fixed 된 컬럼이 글자가 안보이네요

    아까 가르쳐 준데로 했는데도요~~

    다시한번 부탁드립니다.

    > > with StringGrid1.Canvas do

    > > begin

    > > if (gdFixed in State) then

    > > begin

    > > Brush.Color := $00FF80FF;

    > > Font.Color := clBlack;

    > > FillRect(Rect);

    > > end else if (StringGrid1.Cells[1,I] <> StringGrid1.Cells[7,I]) then

    > > begin

    > > Font.Color := clBlack;

    > > Brush.Color := clPurple;

    > > FillRect(Rect);

    > > end else

    > > begin

    > > Font.Color := clWindowText;

    > > Brush.Color := clWindow;

    > > FillRect(Rect);

    > > end;

    > > end;

    > //////////////////////////////////////////////////////////////////

    > FillRect으로 셀을 채운후 글자는 TextRect로 다시 써야보입니다

    > 일단 아래것을 참고해보세요

    > procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

    > Field: TField; State: TGridDrawState);

    > begin

    >

    > with TDBGrid(Sender) do begin

    > if (SelectedRows.CurrentRowSelected) then begin //현선택된줄만 색칠하기

    > Canvas.Brush.Color := clYellow;

    > Canvas.Font.Color := clBlack;

    > Canvas.FillRect(Rect);

    > //필드타입에 따라 다시쓰는 위치를 조정하세요.

    > if Field.DataType = ftString then

    > canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, Field.AsString)

    > else

    > canvas.TextRect(Rect, Rect.Right - canvas.TextWidth(Field.AsString)

    > - 3, Rect.Top, Field.AsString)

    > end;

    > end;

    > end;

  • Profile
    홍성락 2001.11.22 02:15
    꼴통 wrote:

    > 저렇게 코딩해서 그리드의 셀을 비교해서 특정셀만 색깔이 바꿔어야 되거든요..

    > 그리고 스트링 그리드의 Fixed 된 컬럼이 글자가 안보이네요

    > 아까 가르쳐 준데로 했는데도요~~

    > 다시한번 부탁드립니다.

    > > > with StringGrid1.Canvas do

    > > > begin

    > > > if (gdFixed in State) then

    > > > begin

    > > > Brush.Color := $00FF80FF;

    > > > Font.Color := clBlack;

    > > > FillRect(Rect);

    > > > end else if (StringGrid1.Cells[1,I] <> StringGrid1.Cells[7,I]) then

    > > > begin

    > > > Font.Color := clBlack;

    > > > Brush.Color := clPurple;

    > > > FillRect(Rect);

    > > > end else

    > > > begin

    > > > Font.Color := clWindowText;

    > > > Brush.Color := clWindow;

    > > > FillRect(Rect);

    > > > end;

    > > > end;

    > > //////////////////////////////////////////////////////////////////

    > > FillRect으로 셀을 채운후 글자는 TextRect로 다시 써야보입니다

    > > 일단 아래것을 참고해보세요

    > > procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

    > > Field: TField; State: TGridDrawState);

    > > begin

    > >

    > > with TDBGrid(Sender) do begin

    > > if (SelectedRows.CurrentRowSelected) then begin //현선택된줄만 색칠하기

    > > Canvas.Brush.Color := clYellow;

    > > Canvas.Font.Color := clBlack;

    > > Canvas.FillRect(Rect);

    > > //필드타입에 따라 다시쓰는 위치를 조정하세요.

    > > if Field.DataType = ftString then

    > > canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, Field.AsString)

    > > else

    > > canvas.TextRect(Rect, Rect.Right - canvas.TextWidth(Field.AsString)

    > > - 3, Rect.Top, Field.AsString)

    > > end;

    > > end;

    > > end;

    //////////////////////////////////////////////////////////////////////////

    예제는 디비그리드나 스트링그리드나 캠퍼스사용방법은 비슷합니다.

    FillRect(Rect); 다음에 를 쓰세요,

    아래 예는 문자를 왼쪽에서 시작하는것입니다.

    TextRect(Rect,Rect.Left+3, (Rect.Top+Rect.Bottom-StringGrid1.Font.Size-4) div 2 , StringGrid1.Cells[ACol, ARow]);

    --------------------------------------------------------------------------

    위에 여러조건에 따라 FillRect(Rect);를 하셨잖아요

    조건에 따라 TextRect(Rect, X, Y, StringGrid1.Cells[ACol, ARow]);

    에서 X와Y를 바꿔주면 왼쪽/오른쪽/가운데 정렬을 합니다.



    Re: 빠른 답변 부탁드립니다.[스트링그리드 문자포멧형식] 제목으로 게시판에서 찾아보세요.