0
我有畫布DrawText的問題,我剛剛從文字我想顯示第4個字符。爲什麼DrawText只打印我的字符串的前四個字符?
作爲例子我有文字'離線'它會顯示'offl'。
這段代碼有什麼問題。
代碼
procedure TStatusCombo.Paint ;
var DrawRect : TRect ;
StatusColor : TColor ;
iTextWidth : Integer ;
r : TRect ;
begin
DrawRect := ClientRect ;
//colors
Canvas.Brush.Style := bsClear ; //transparent background
Canvas.Brush.Color := Tcolor($4D4D4D) ;
Canvas.Pen.Color := Tcolor($4D4D4D) ;
Canvas.RoundRect(DrawRect.Left , DrawRect.Top ,
DrawRect.Right , DrawRect.Bottom , 15, 15);
//Drawing
//SetRect(DrawRect, DrawRect.Left+3, DrawRect.Top+3, DrawRect.Right-3, DrawRect.Bottom-3);
case ChatStatus of
sNormal: StatusColor := TColor($00FF78) ;
sOnline: StatusColor := TColor($00FF78) ;
sBusy: StatusColor := TColor($00FF78) ;
sAway: StatusColor := TColor($00FF78) ;
sOffline:StatusColor := TColor($00FF78) ;
end;
Canvas.Brush.Color := StatusColor ;
Canvas.RoundRect(DrawRect.Right - 20 , DrawRect.Top +4 ,
DrawRect.Right -10 , DrawRect.Bottom -4 , 5, 5);
FCaption := FStatusText[ChatStatus];
Canvas.Brush.Style := bsClear ;
Canvas.Font.Color := clWhite ;
DrawText(Canvas.Handle,pchar(FCaption) ,sizeof(FCaption),DrawRect ,DT_VCENTER or DT_CENTER or DT_SINGLELINE);
end;
謝謝安德烈亞斯,它的工作完美了。 – Realbitt 2012-07-14 10:58:50
最簡單的就是傳遞-1而不是Length() – 2012-07-14 12:43:50