掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
StringGrid内の文字の一部に色をつけるには? (ID:41302)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
特にDrawTextにこだわる必要がなければ、TextOutで座標を計算しながら1文字ずつ出力していくのもありかと。 var str: WideString; c: WideChar; x, y: Integer; i: Integer; ... with StringGrid1 do begin Canvas.Font := Font; // 描画するフォントを割り当てておく str := Cells[ACol, ARow]; // 描画する文字 x := Rect.Left + 4; // 左に少し余白を開ける y := (Rect.Top + Rect.Bottom - Canvas.TextHeight(str)) div 2; // 縦方向は中央揃え for i := 1 to Length(str) do begin c := str[i]; case c of // 文字に応じて描画色を決める '2', '4': Canvas.Font.Color := clRed else Canvas.Font.Color := Font.Color; end; Canvas.TextOut(x, y, c); // 1文字出力して... Inc(x, Canvas.TextWidth(c)); // 次の文字に進む end; end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.