
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:

I use Delphi XE8
pls help me.
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
Here is my image of it in operation with exactly the code shown

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With