掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
TStringGridのTPopupColumnの文字サイズの変更 (ID:152141)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
お世話になります。 Delphi12.0のFMXでアプリを開発しようと思っていますが、困った点がありまして質問させて頂きます。 TStringGridでTPopupColumnを使用しなくてはならないのですが、文字サイズがどうしてもデフォルトのままで変更が効きません。 ChatGPTと何度かやり取りしまして(※結構動かないコードを提示されますね)、最終的に出されたコードは次の通りなのですが、これでも反映されない感じです。 何かヒントを頂けますと幸いです。 <ChatGPTから出されたコード> const COL_POPUP = 0; // 対象の TPopupColumn の列インデックス FONT_SIZE = 16; // フォントサイズ ITEM_HEIGHT = 28; // ドロップダウンのアイテム高さ procedure TForm1.StringGrid1CreateCustomEditor(Sender: TObject; const Column: TColumn; var Control: TStyledControl); var PB : TPopupBox; PC : TPopupColumn; CurText: string; begin if Column.Index <> COL_POPUP then Exit; PC := Column as TPopupColumn; PB := TPopupBox.Create(StringGrid1); PB.Stored := False; // スタイルのサイズ上書きを許可(サイズはスタイルに従わない) PB.StyledSettings := PB.StyledSettings - [TStyledSetting.Size]; // 選択肢を列の Items からコピー PB.Items.Assign(PC.Items); // イベント(★通常のメソッドを割り当てる) PB.OnApplyStyleLookup := PopupBoxApplyStyle; // ドロップダウン/表示部の見た目調整 // 現在セルの値で初期選択を合わせる CurText := StringGrid1.Cells[Column.Index, StringGrid1.Row]; PB.ItemIndex := PB.Items.IndexOf(CurText); Control := PB; end; procedure TForm1.PopupBoxApplyStyle(Sender: TObject); var PB : TPopupBox; Txt: TText; LB : TListBox; i : Integer; It : TListBoxItem; ItText: TText; begin PB := TPopupBox(Sender); // セルに見えている文字('text' リソース)のフォント Txt := PB.FindStyleResource('text') as TText; if Txt <> nil then Txt.Font.Size := FONT_SIZE; // ドロップダウンの ListBox と各アイテムのフォント・高さ LB := PB.FindStyleResource('listbox') as TListBox; if LB <> nil then begin LB.ItemHeight := ITEM_HEIGHT; for i := 0 to LB.Count - 1 do begin It := LB.ItemByIndex(i) as TListBoxItem; if It <> nil then begin ItText := It.FindStyleResource('text') as TText; if ItText <> nil then ItText.Font.Size := FONT_SIZE; end; end; end; end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.