3

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.

Community
  • 1
  • 1
smartiz
  • 151
  • 7
  • 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 Sep 01 '15 at 18:12
  • @asd-tm hi. I've edited my post. pls check it. – smartiz Sep 01 '15 at 18:30
  • 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 Sep 02 '15 at 08:01

1 Answers1

1

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

Dsm
  • 5,870
  • 20
  • 24
  • ty. but there are many problems with items drawing... There are also problem with the drawing border around selected item in csOwnerDrawFixed mode... sample shot : http://i.imgur.com/NKzBIEd.png – smartiz Sep 03 '15 at 11:11
  • It was only meant as a starting point - you will need to do some work yourself. I don't know what other options you have set and maybe using styles messes things up - I certainly don't have the text drawing twice like your image. For me everything works fine - the text is shown blue around the selected item, but I agree you that you may need to improve it by looking at the State parameter - as I commented in my code. – Dsm Sep 03 '15 at 11:24