掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
STRINNGGRIDの固定列のみフォントを指定するには (ID:30508)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
ん〜、前の書き込みから考えるに何か誤解しているような気がします。 (していなかったらごめんなさい。) 今回の場合、StringGridの標準描画をoff(DefaultDrawing=False)にして、 OnDrawCellに自前の描画ルーチンを書いてあげることで実現可能だと思います。 標準描画された後に文字を表示しているから2重に表示される。 FillRectで文字が表示された後に、ベタで塗りつぶしをしているから、 1つ目の文字が消去され、2回目の文字描画だけが残り 文字が1つになったように見える。 要するに、標準描画機能が邪魔なわけです。 DefaultDrawingをFalseにして OnDrawCellイベントに、以下のプログラムを追加してみてください。 他の属性は考えてみてくださいね。 procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with StringGrid1.Canvas do begin // 条件による各種設定 if gdFixed in State then begin // ========== 固定行設定 Brush.Color := StringGrid1.FixedColor; // ========== 文字設定 Font := StringGrid1.Font; Font.Name := 'MS ゴシック'; end else if (gdSelected in State) and Not(gdFocused in State) then begin // ========== 選択状態でフォーカスがない場合の設定 Brush.Color := clHighLight; // ========== 文字設定 Font := StringGrid1.Font; Font.Color := clWindow; end else begin // ========== 通常状態・フォーカス状態の色 Brush.Color := StringGrid1.Color; // ========== 文字設定 Font := StringGrid1.Font; end; // ========== 下地描画 FillRect(Rect); // ========== 文字描画 InflateRect(Rect, -2, -2); DrawText(Handle, PChar(StringGrid1.Cells[ACol, ARow]), -1, Rect, DT_VCENTER or DT_CENTER or DT_SINGLELINE); InflateRect(Rect, 2, 2); // ========== 固定行影描画 if (gdFixed in State) and StringGrid1.Ctl3D then begin Pen.Color := clBtnHighlight; Polyline([Point(Rect.Left, Rect.Bottom - 1), Rect.TopLeft, Point(Rect.Right, Rect.Top)]); end; // ========== フォーカス枠描画 if gdFocused in State then DrawFocusRect(Rect); end; end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.