掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
文字列省略時の...の位置 (ID:32740)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
DT_PATH_ELLIPSISは、ファイルPATHでない普通の文字列の省略には むかないね。 function MinimizeString(const aStr: string; Canvas: TCanvas; MaxWidth: Integer; isMiddle: Boolean=True; LeftLen: Integer=3): string; const MINIMIZESTR = '...'; var i, cWidth, fWidth: Integer; pT, pL, pB: PChar; cc: Char; sLeft: string; begin result := aStr; if (Canvas.TextWidth(aStr) < MaxWidth) then exit; pT := PChar(aStr); cWidth := Canvas.TextWidth(MINIMIZESTR); if not isMiddle then begin while (Canvas.TextWidth(pT) + cWidth > MaxWidth) do begin if IsDBCSLeadByte(Byte(pT^)) then inc(pT, 2) else inc(pT); end; result := MINIMIZESTR + pT; end else begin pL := pT + Length(aStr); pB := pT; for i:=1 to LeftLen do begin if IsDBCSLeadByte(Byte(pB^)) then inc(pB, 2) else inc(pB); end; cc := pB^; pB^ := #0; sLeft := pT; fWidth := Canvas.TextWidth(sLeft) + cWidth; pB^ := cc; while (Canvas.TextWidth(pB) > MaxWidth - fWidth) do begin if pB > pL then break; if IsDBCSLeadByte(Byte(pB^)) then inc(pB, 2) else inc(pB); end; result := sLeft + MINIMIZESTR + pB; end; end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.