delphi - 当 BiDiMode= bdRightToLeft 和 Style= csDropDownList 且应用程序使用 VCL 样式时,TComboBoxEx 项目无法正确绘制

标签 delphi delphi-xe8 vcl-styles tcombobox

enter image description here enter image description here

嗨。

当 BiDiMode= bdRightToLeft 和 Style= csDropDownList 且应用程序使用 VCL 样式时,TComboBoxEx 项目无法正确绘制;在下拉列表中,左侧绘制的图标和文字,当选择一个项目时,左侧绘制的图标和文字将会消失!

我看到了Right to left ComboBox in Delphi XE2 with styles但没有帮助我。

我应该如何纠正它并在 ComboBoxEx 右侧绘制图标和文本(第一个图标和下一个图标)?

这正是我所需要的,我用 Photoshop 设计了这个示例:

enter image description here

我使用Delphi XE8

请帮助我。

最佳答案

BiDiMode 适用于从右向左书写的语言,因此并不真正适合您的需求。

我找不到使用 TComboBoxEx 实现此操作的方法,但您可以相当轻松地使用 TComboBox 实现此操作。

添加一个TComboBox并使其样式为csOwnerDrawFixed。我在下面的代码中假设了 TImageList(您必须已经拥有)和 TComboBox 的基本名称。您需要将其修改为您自己的名称。添加一个 OnDrawItem 事件,类似于下面的事件。 (你可能想稍微调一下)。

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  iImageWidth, iTextWidth, iMargin : integer;
  iText : string;
  iCanvas : TCanvas;
begin
  // draw image at right and text right justify
  // assume image index = Item for now.
  iCanvas := ComboBox1.Canvas;
  // need to check state; Just ignore for now.
  iImageWidth := ImageList1.Width;
  iMargin := 4; // pixels - can calculate instead
  iText := ComboBox1.Items[ Index ];
  iTextWidth := iCanvas.TextWidth( iText);

  ImageList1.Draw( iCanvas, Rect.Right - iImageWidth - iMargin, Rect.Top, Index );
  iCanvas.TextOut( Rect.Right - 2 * iMargin - iTextWidth - iImageWidth, Rect.Top, iText);
end;

我测试过,效果很好

更新

这是我的运行图像,其中显示的代码完全相同 Dropped down

关于delphi - 当 BiDiMode= bdRightToLeft 和 Style= csDropDownList 且应用程序使用 VCL 样式时,TComboBoxEx 项目无法正确绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32337779/

相关文章:

delphi - 如何更改标签的dragmode属性(firemonkey)

android - 如何指定Android服务标签(android :label for the <service> tag) in AndroidManifest. xml?(RAD Studio,Delphi XE)

delphi - 为什么在我的程序开始之前 GetLastError 出现错误?

delphi - 如何在Delphi调用堆栈窗口中隐藏 'non-user'堆栈帧?

delphi - 如何获取TSynEdit等TWinControl的水平和垂直滚动条位置?

delphi - 选项卡的关闭按钮不支持 vcl 样式

delphi - 使用 VCL 样式对 TOpenDialog 和 TOpenPictureDialog 进行换肤

delphi - 如何申请 TLinkLabel 的 VCLStyle

delphi - 根据过滤字符串检查 TDataSet 行

delphi - Delphi TBitBtn白色层