掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
Stringgridのセル内複数行表示の色つけについて (ID:45766)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
procedure TForm3.FormCreate(Sender: TObject); begin StringGrid1.Cells[1,1] := '父'#13#10'母'; StringGrid1.Cells[2,1] := '父母'; end; procedure TForm3.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;Rect: TRect; State: TGridDrawState); var Text: String; I,H: Integer; S1,S2: String; BRect: TRect; begin if not ( gdFixed in state ) then begin StringGrid1.Canvas.Brush.Color := StringGrid1.Color; StringGrid1.Canvas.FillRect(Rect); Text := StringGrid1.Cells[ACol,ARow]; //CELLのText I := Pos ( #13#10,Text); //#13#10の位置取得 if ( I <> 0 ) then begin S1 := Copy(Text,0,I); //#13#10より前の文字 S2 := Copy(Text,I+2,Length(Text)-I); //#1310より後ろの文字 H := StringGrid1.Canvas.TextHeight(S1); //前の文字の高さ //#13#10の前を描画 StringGrid1.Canvas.Font.Color := clRed; StringGrid1.Canvas.TextRect(Rect,Rect.Left,Rect.Top,S1); //#13#10の後を描画 BRect := Rect; BRect.Top := BRect.Top + H; StringGrid1.Canvas.Font.Color := clBlue; StringGrid1.Canvas.TextRect(BRect,Rect.Left,Rect.Top+H,S2); end else begin //#13#10の無いCELL StringGrid1.Canvas.Font.Color := StringGrid1.Font.Color; StringGrid1.Canvas.TextRect(Rect,Text); end; end; end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.