掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
TListViewで行の高さを低く設定したときの実際の高さを取得するには (ID:150579)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
うーむ,趣旨が理解し難いというか,何と言ったらいいのか. 以下のコードを試してみてください. unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls; type TListView = class(Vcl.ComCtrls.TListView) private FItemHeight : UInt; procedure SetItemHeight(const Value: UInt); protected procedure CNMeasureitem(var Message: TWMMeasureItem); message CN_MEASUREITEM; public property ItemHeight : UInt read FItemHeight write SetItemHeight; end; TForm1 = class(TForm) Button1: TButton; ListView1: TListView; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure ListView1DrawItem(Sender: TCustomListView; Item: TListItem; Rect: TRect; State: TOwnerDrawState); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.dfm} //============================================================================= // フォーム生成時の処理 // // 本サンプルの動作確認は以下 // Windows 10 ビルド 19043 Pro 64 bit + Delphi XE5(UP2) Pro VCL-32 //============================================================================= procedure TForm1.FormCreate(Sender: TObject); var LCol : TListColumn; LItem : TListItem; LIndex: Integer; begin ListView1.ViewStyle := vsReport; ListView1.OwnerDraw := True; ListView1.ItemHeight := 4; ListView1.Items.BeginUpdate; LCol := ListView1.Columns.Add; LCol.Caption := 'Test Items'; LCol.Width := 200; for LIndex := 0 to 49 do begin LItem := ListView1.Items.Add; LItem.Caption := Format(' %.6d',[LIndex + 1]); end; ListView1.Items.EndUpdate; end; //============================================================================= // ListView1 の行の高さを変更 //============================================================================= procedure TForm1.Button1Click(Sender: TObject); begin ListView1.ItemHeight := ListView1.ItemHeight + 2; end; //============================================================================= // ListView1 の OnDrawItem イベント //============================================================================= procedure TForm1.ListView1DrawItem(Sender: TCustomListView; Item: TListItem; Rect: TRect; State: TOwnerDrawState); begin ListView1.Canvas.TextOut(Rect.Left, Rect.Top, Item.Caption); end; { TListView } //----------------------------------------------- ------------------------- // TListView の CN_MEASUREITEM メッセージ処理 // CN_MEASUREITEM は,コントロール生成時に自身に送信されてくるメッセージ // ItemHeight の値を設定 // OwnerDraw の値が True でないと機能しない //----------------------------------------------- ------------------------- procedure TListView.CNMeasureitem(var Message: TWMMeasureItem); begin inherited; Message.MeasureItemStruct.itemHeight := FItemHeight; end; //----------------------------------------------- ------------------------- // ItemHeight プロパティの設定用メソッド //----------------------------------------------- ------------------------- procedure TListView.SetItemHeight(const Value: UInt); var LTopIndex : Integer; begin if Value <> FItemHeight then begin FItemHeight := Value; if Items.Count > 1 then begin LTopIndex := TopItem.Index; Selected := nil; RecreateWnd; Scroll(0, LTopIndex * FItemHeight); end; end; end; end.
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.