Q&A

  • String Grid에서 오른쪽 정렬을 할 수 없나요?
스트링그리드는 참 좋은 콤포넌트이긴 한데,

몇가지 안되는게 있는 것 같아요.



오른족 정렬을 하고 싶어요.

물론, 전부다가 아니라, 몇몇 칼럼은 왼쪽 정렬, 몇몇칼럼은 오른쪽 정렬 이렇게요.



칼럼마다 정렬을다르게 하고 싶은데...



방법이 있을까요..?

2  COMMENTS
  • Profile
    버섯 2001.12.20 18:29
    훈 wrote:

    > 스트링그리드는 참 좋은 콤포넌트이긴 한데,

    > 몇가지 안되는게 있는 것 같아요.

    >

    > 오른족 정렬을 하고 싶어요.

    > 물론, 전부다가 아니라, 몇몇 칼럼은 왼쪽 정렬, 몇몇칼럼은 오른쪽 정렬 이렇게요.

    >

    > 칼럼마다 정렬을다르게 하고 싶은데...

    >

    > 방법이 있을까요..?



    Ondrawcell 이라는 이벤트가 있습니다.

    거기다가 임의로 그려넣어야 합니다..

    예제는 여기 많이 있는데...



    아래꺼 보고 참조하시길..



    procedure TfrmMain.sgMemberDrawCell(Sender: TObject; ACol, ARow: Integer;

    Rect: TRect; State: TGridDrawState);

    var

    LeftPos: Integer;

    TopPos : integer;

    CellStr: string;

    rr : TGridRect;

    begin



    TStringGrid(Sender).ColWidths[aCol] := fMember[aCol].ColumnWidth;

    with TStringGrid(Sender).Canvas do

    begin

    CellStr := TStringGrid(Sender).Cells[ACol, ARow];

    if aRow = 0 then CellStr := fMember[aCol].Title;



    if (aCol <> 0) and (aRow <> 0) then

    begin

    Font.Color := fMember[aCol].FontColor;

    Brush.Color := fMember[aCol].BackColor;

    end;

    TopPos := ((Rect.Top - Rect.Bottom -TStringGrid(Sender).Canvas.TextHeight(CellStr)) div 2) + Rect.Bottom;



    if fMember[aCol].Alignment = taCenter then

    begin

    LeftPos := ((Rect.Right - Rect.Left - TStringGrid(Sender).Canvas.TextWidth(CellStr)) div 2) + Rect.Left;

    end

    else if fMember[aCol].Alignment = taLeftjustify then

    begin

    LeftPos := Rect.Left + 2;

    end

    else

    begin

    LeftPos := (Rect.Right - Rect.Left - TStringGrid(Sender).Canvas.TextWidth(CellStr)) + Rect.Left;

    end;



    if aRow = 0 then

    LeftPos := ((Rect.Right - Rect.Left - TStringGrid(Sender).Canvas.TextWidth(CellStr)) div 2) + Rect.Left;



    FillRect(Rect);

    TextOut(LeftPos, TopPos, CellStr);

    end;

    end;



  • Profile
    2001.12.20 18:54
    버섯 wrote:

    > 훈 wrote:

    > > 스트링그리드는 참 좋은 콤포넌트이긴 한데,

    > > 몇가지 안되는게 있는 것 같아요.

    > >

    > > 오른족 정렬을 하고 싶어요.

    > > 물론, 전부다가 아니라, 몇몇 칼럼은 왼쪽 정렬, 몇몇칼럼은 오른쪽 정렬 이렇게요.

    > >

    > > 칼럼마다 정렬을다르게 하고 싶은데...

    > >

    > > 방법이 있을까요..?

    >

    > Ondrawcell 이라는 이벤트가 있습니다.

    > 거기다가 임의로 그려넣어야 합니다..

    > 예제는 여기 많이 있는데...

    >

    > 아래꺼 보고 참조하시길..

    >

    > procedure TfrmMain.sgMemberDrawCell(Sender: TObject; ACol, ARow: Integer;

    > Rect: TRect; State: TGridDrawState);

    > var

    > LeftPos: Integer;

    > TopPos : integer;

    > CellStr: string;

    > rr : TGridRect;

    > begin

    >

    > TStringGrid(Sender).ColWidths[aCol] := fMember[aCol].ColumnWidth;

    > with TStringGrid(Sender).Canvas do

    > begin

    > CellStr := TStringGrid(Sender).Cells[ACol, ARow];

    > if aRow = 0 then CellStr := fMember[aCol].Title;

    >

    > if (aCol <> 0) and (aRow <> 0) then

    > begin

    > Font.Color := fMember[aCol].FontColor;

    > Brush.Color := fMember[aCol].BackColor;

    > end;

    > TopPos := ((Rect.Top - Rect.Bottom -TStringGrid(Sender).Canvas.TextHeight(CellStr)) div 2) + Rect.Bottom;

    >

    > if fMember[aCol].Alignment = taCenter then

    > begin

    > LeftPos := ((Rect.Right - Rect.Left - TStringGrid(Sender).Canvas.TextWidth(CellStr)) div 2) + Rect.Left;

    > end

    > else if fMember[aCol].Alignment = taLeftjustify then

    > begin

    > LeftPos := Rect.Left + 2;

    > end

    > else

    > begin

    > LeftPos := (Rect.Right - Rect.Left - TStringGrid(Sender).Canvas.TextWidth(CellStr)) + Rect.Left;

    > end;

    >

    > if aRow = 0 then

    > LeftPos := ((Rect.Right - Rect.Left - TStringGrid(Sender).Canvas.TextWidth(CellStr)) div 2) + Rect.Left;

    >

    > FillRect(Rect);

    > TextOut(LeftPos, TopPos, CellStr);

    > end;

    > end;

    >