【发布时间】:2016-05-09 10:58:09
【问题描述】:
我在 Delphi Seattle 有一个所有者绘制的 TComboBox,它忽略了 DropDownCount 属性的任何设置。单个项目的高度为 59 像素,宽度为 311 像素。我在Items 字符串列表中有 5 个条目。将值设置为低于 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.
【问题讨论】:
-
推荐阅读:Welcome to SO 和Help Center 尤其是关于提问的。
-
我无法重现您描述的行为。请提供Minimal, Complete, and Verifiable example
-
我们无法调试我们看不到的代码。如果您需要代码方面的帮助,我们需要能够看到代码。
-
道歉。我认为这是一个已知问题,我不知何故无法在线找到修复程序。我会在几分钟内发布一个最小的应用程序来重现这个错误。 (导致问题的实际代码是(a)巨大的和(b)专有的,所以不能发布。)同时,我发现如果我增加 Items 字段中的总条目,我可以在下拉列表中获得更多条目但仍然与下拉计数不同;文档说,如果您输入的条目少于总条目,则下拉列表将限制为总数,因此可能会出现问题...
-
我在西雅图没有这个问题,但我在柏林有。当我为 FMX Win32 编译时。不过在 Android 上没问题。
标签: delphi delphi-10-seattle tcombobox