我TComboBox
在西雅图德尔福有一个业主自画的,它忽略了该DropDownCount
物业的任何设置。单个项目的高度为 59 像素,宽度为 311 像素。我在字符串列表中有 5 个条目Items
。将值设置为低于 8 会导致根本不显示下拉菜单,而任何更高的值都会导致下拉菜单中仅显示 1 个项目以及垂直滚动条。我需要能够在下拉列表的项目列表中显示所有 5 个条目。
这是重现问题的 DFM:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 223
ClientWidth = 527
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ComboBox1: TComboBox
Left = 96
Top = 16
Width = 311
Height = 22
Style = csOwnerDrawVariable
ItemIndex = 0
TabOrder = 0
Text = 'ITEM ONE'
OnDrawItem = ComboBox1DrawItem
OnMeasureItem = ComboBox1MeasureItem
Items.Strings = (
'ITEM ONE'
'ITEM TWO'
'ITEM THREE'
'ITEM FOUR'
'ITEM FIVE')
end
end
这是 PAS 文件:
unit CBBoxBugUnit;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure ComboBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var Working_String : String;
Text_Width ,
Text_Height ,
Output_X ,
Output_Y : Integer;
begin
ComboBox1.Canvas.Pen.Color := clWhite;
ComboBox1.Canvas.Brush.Color := clGreen;
ComboBox1.Canvas.Brush.Style := bsSolid;
ComboBox1.Canvas.Pen.Style := psSolid;
ComboBox1.Canvas.Pen.Width := 1;
ComboBox1.Canvas.Font.Color := clWhite;
ComboBox1.Canvas.Font.Name := 'ARIAL BLACK';
ComboBox1.Canvas.Font.Size := 14;
ComboBox1.Canvas.FillRect( Rect );
Working_String := self.ComboBox1.Items.Strings[ Index ];
Text_Width := self.ComboBox1.Canvas.TextWidth( Working_String );
Text_Height := self.ComboBox1.Canvas.TextHeight( Working_String );
Output_X := ( Rect.Width - Text_Width ) div 2;
Output_Y := ( Rect.Height - Text_Height ) div 2;
ComboBox1.Canvas.TextOut( Output_X , Output_Y , Working_String );
end;
procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
begin
Height := 59;
end;
end.