掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DBGridのタイトルを複数行表示するには? (ID:31057)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
これの事ですか?。 unit MutiTitleDBGroid; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, DBGrids, Grids; type TMutiTitleDBGrid = class(TDBGrid) private { Private 宣言 } procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override; protected { Protected 宣言 } public { Public 宣言 } published { Published 宣言 } end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMutiTitleDBGrid]); end; { TMutiTitleDBGrid } procedure TMutiTitleDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState); const AlignFlags : array [TAlignment] of Integer = ( DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX, DT_RIGHT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX, DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX ); var Text : string; Flags: LongInt; begin inherited DrawCell(ACol, ARow, ARect, AState); if (ARow = 0) and (ACol <> 0) and (FieldCount > 0) then begin // 縁を残して塗りつぶす InflateRect(ARect, -1, -1); Canvas.FillRect(ARect); // DBGridのTitleFontプロパティを使う Canvas.Font.Assign(TitleFont); // カラムのTitle.Captionを使用する Text := Columns[ACol-1].Title.Caption; // 文字列に";"があるかを判断して2行に分ける if (Pos(';', Text) > 0) then begin // 2行の場合 Flags := DT_VCENTER or AlignFlags[Columns[ACol-1].Title.Alignment]; // 文字列を分割し、CRLFを入れる Text := Copy(Text, 1, Pos(';', Text)-1) + #13+#10 + Copy(Text, Pos(';', Text)+1, Length(Text)); end else // 1行の場合DT_SINGLELINEを付けて行の真ん中に表示する Flags := DT_SINGLELINE or DT_VCENTER or AlignFlags[Columns[ACol-1].Title.Alignment]; // 表示 DrawText(Canvas.Handle, PChar(Text), Length(Text), ARect, Flags); end; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.