3
votes

enter image description here enter image description here

hi.

TComboBoxEx item isn't drawing correctly when BiDiMode= bdRightToLeft and Style= csDropDownList and application use VCL Style; in DropDown list, icon and text drawn on the left and when selecting an item, icon drawn on left side and text will disappeared!

i saw Right to left ComboBox in Delphi XE2 with styles but did not help me.

what should I do to correct it and painting icon and text (first icon and next,text) on the right side of ComboBoxEx ?

This is exactly what I need, and I designed this sample with Photoshop:

enter image description here

I use Delphi XE8

pls help me.

1
I failed to reproduce the bug in XE5. The item is displayed in the following way - dropdown button - most left - image and text on the left without spaces. Please, provide MCVE.asd-tm
@asd-tm hi. I've edited my post. pls check it.smartiz
Hi. Now I understand what exactly you want. I have deleted my answer. hope, that zero answer score will attract attention of the community to your question.asd-tm

1 Answers

1
votes

BiDiMode is intended for languages that write from right to left, so is not really applicable to your needs.

I couldn't see a way to do it with TComboBoxEx, but you can do it with TComboBox fairly easily.

Add a TComboBox and make its style csOwnerDrawFixed. I have in the code below assumed basic names for TImageList (which you must already have) and TComboBox. You will need to modify it for your own names. Add an OnDrawItem Event, similar to that below. (You may want to tart it up a bit).

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;

I have tested it and it works fine

Update

Here is my image of it in operation with exactly the code shown Dropped down