2013-07-21 8 views
0

양식이 있습니다. formshow에서 필드의 값을 stringgrid 셀로 초기화하지만 셀의 텍스트 아래에 그림자가 표시됩니다. 필자는 필드 값에 페르시아 문자를 사용했습니다.
영어 값과 동일하게 적용했지만 제대로 작동합니다.
의견을 보내 주시면 감사하겠습니다. 출력의StringGrid 아래의 그림자

예 : OnDrawCell를 입력하면 텍스트가 이미 렌더링됩니다 enaabled DefaultDrawing

enter image description here

+3

TextOut을 사용하기 전에 DrawCell을 구현하고 Rect를 채우지 않은 것처럼 보입니다. – bummi

+0

s : = (Sender as TStringGrid) .Cells [ACol, ARow]; 길이가 0보다 큰 경우 시작 drawrect : = Rect; DrawText ((보낸 사람 : TStringGrid) .Canvas.handle, Pchar (s), 길이, drawrect, DT_CALCRECT 또는 DT_WORDBREAK 또는 DT_LEFT); if (drawrect.bottom - drawrect.Top)> (보낸 사람 : TStringGrid) .RowHeights [ARow] 다음에 (보낸 사람 : TStringGrid) .RowHeights [ARow] : = (drawrect.bottom - drawrect.Top) else drawrectrect begin . 오른쪽 : = Rect.Right; (보낸 사람 : TStringGrid) .Canvas.FillRect (drawrect); DrawText ((보낸 사람 : TStringGrid) .Canvas.handle, Pchar (s), Length (s), drawrect, DT_WORDBREAK 또는 DT_LEFT); 끝; –

+0

s의 길이에 따라 처리 방법이 달라질 수는 없지만 첫 번째 루틴으로'(Sender as TStringGrid) .Canvas.FillRect (Rect);'를 추가하면 문제는 하나 였을 것입니다. DefaultDrawing 'rext는 이미 그리드에 그려져있을 것입니다. – bummi

답변

2

.

당신은 FillRect로 삭제/작성되어야한다 Rect 느릅 나무를 계산에 DrawTextDT_CALCRECT 당신이해야합니다 사용하여 그림에 필요한 rowHeight를 계산하기 때문에.
UnionRect을 사용하여 채워야하는 마지막 Rect를 얻을 수 있습니다 (예제에서는 FillRect).

procedure TForm1.FormCreate(Sender: TObject); 
begin 
    StringGrid1.Cells[1,1] := 'Hallo'#13'World'; 
    StringGrid1.Cells[2,2] := 'اهای' +13# + 'جهان'; 
end; 

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; 
    Rect: TRect; State: TGridDrawState); 
var 
    S:String; 
    drawrect,Fillrect : TRect; 
begin 
    s := (Sender as TStringGrid).Cells[ACol, ARow]; 
    drawrect := Rect; 
    DrawText((Sender as TStringGrid).Canvas.handle, Pchar(s), Length(s), 
     drawrect, DT_CALCRECT or DT_WORDBREAK or DT_LEFT); 
    if (drawrect.bottom - drawrect.Top) > (Sender as TStringGrid) 
     .RowHeights[ARow] then (Sender as TStringGrid) 
     .RowHeights[ARow] := (drawrect.bottom - drawrect.Top); 
    UnionRect(FillRect,Rect,DrawRect); 
    (Sender as TStringGrid).Canvas.FillRect(FillRect); 
    DrawText((Sender as TStringGrid).Canvas.handle, Pchar(s), Length(s), 
     drawrect, DT_WORDBREAK or DT_LEFT); 
end;