从右到左在Delphi XE2中具有样式的ComboBox [英] Right to left ComboBox in Delphi XE2 with styles

查看:170
本文介绍了从右到左在Delphi XE2中具有样式的ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在具有自定义样式(Emerald Light Slate)和以下属性的Delphi XE2中使用ComboBox时遇到问题:

I have problems when I use ComboBox in Delphi XE2 with Custom styles(Emerald Light Slate) and this property:

BiDiMode := bdRightToLeft;
Style := csDropDownList;

没有自定义样式的ComboBox:

That ComboBox without Custom style:

并且具有自定义样式(Emerald Light Slate):

And with Custom styles(Emerald Light Slate):

我该如何解决?

推荐答案

问题似乎位于 TComboBox ),您可以修复此方法以覆盖此方法.

The issue it seems located in the DrawItem method of the TComboBoxStyleHook (the vcl style hook of the TComboBox), you can fix this overriding this method.

尝试以下示例代码(此解决方案远非完美,但只是一个开始)

Try this sample code (this solution is far from being perfect but is a start)

type
  TComboBoxStyleHookFix = class(TComboBoxStyleHook)
  protected
    procedure DrawItem(Canvas: TCanvas; Index: Integer;
      const R: TRect; Selected: Boolean); override;
  end;

{ TComboBoxStyleHookFix }

procedure TComboBoxStyleHookFix.DrawItem(Canvas: TCanvas; Index: Integer;
  const R: TRect; Selected: Boolean);
var
  DIS  : TDrawItemStruct;
  Text : string;
begin
  if Control.BiDiMode<>bdRightToLeft then
   inherited
  else
  begin
    FillChar(DIS, SizeOf(DIS), 0);
    DIS.CtlType := ODT_COMBOBOX;
    DIS.CtlID := GetDlgCtrlID(Handle);
    DIS.itemAction := ODA_DRAWENTIRE;
    DIS.hDC := Canvas.Handle;
    DIS.hwndItem := Handle;
    DIS.rcItem := R;
    Text:=TComboBox(Control).Items[Index];    
    DIS.rcItem.Left:=DIS.rcItem.Left+ (DIS.rcItem.Width-Canvas.TextWidth(Text)-5);    
    DIS.itemID := Index;
    DIS.itemData := SendMessage(ListHandle, LB_GETITEMDATA, 0, 0);
    if Selected then
      DIS.itemState := DIS.itemState {or ODS_FOCUS} or ODS_SELECTED;
    SendMessage(Handle, WM_DRAWITEM, Handle, LPARAM(@DIS));
  end;
end;

并以此方式使用

 TStyleManager.Engine.RegisterStyleHook(TComboBox, TComboBoxStyleHookFix);

请不要忘记在Embarcadero的 QC 页中报告此错误.

Don't forget report this bug in the QC page of Embarcadero.

这篇关于从右到左在Delphi XE2中具有样式的ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆