Thread View: borland.public.delphi.vcl.components.using.general
2 messages
2 total messages
Started by Ami Halperin
Thu, 05 Jun 2008 10:43
TComboBox with csOwnerDrawFixed and right aligned text
Author: Ami Halperin
Date: Thu, 05 Jun 2008 10:43
Date: Thu, 05 Jun 2008 10:43
34 lines
2147 bytes
2147 bytes
Hi,
I have implemented a TComboBox with style set csOwnerDrawFixed, It was done
to set the Font of the items without changing the height of the combo (Is
there a different way?).
On DrawItem we draw the text to fit bidimode of right aligned languages:
procedure TBiDiComboBox.OnDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
x : Integer;
txt : String;
begin
Canvas.FillRect(Rect) ;
if BiDiMode = bdRightToLeft then
begin
// align the text to the right
txt := Items[Index];
x := Rect.Right - Canvas.TextWidth(txt) - 4;
Canvas.TextOut(x, Rect.Top, txt);
end
else
begin
if Index >= 0 then
Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
end;
end;
The problem is that on some computers it works fine but on others when you
first drop down the list you see only the left side of the items drawn on
the right side.
After you go over the items with the mouse it works fine.
Do you know of a way to fix it? Is it because of the ComCtl32.dll version?
Thanks in advance,
Chaim
Re: TComboBox with csOwnerDrawFixed and right aligned text
Author: Remy Lebeau (TeamB)
Date: Thu, 05 Jun 2008 18:54
Date: Thu, 05 Jun 2008 18:54
27 lines
1809 bytes
1809 bytes
"Ami Halperin" <Ami_h@mer.co.il> wrote in message
news:4847b55c@newsgroups.borland.com...
> On DrawItem we draw the text to fit bidimode of right aligned languages:
<snip>
I would suggest changing your drawing code to use the Win32 API DrawText()
function instead. TControl has a DrawTextBiDiModeFlags() method. For
example:
procedure TBiDiComboBox.DrawItem(Index: Integer; Rect: TRect; State:
TOwnerDrawState);
var
txt : String;
Flags: Longint;
begin
Canvas.FillRect(Rect) ;
txt := Items[Index];
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or
DT_NOPREFIX);
Windows.DrawText(Canvas.Handle, PChar(txt), Length(txt), Rect,
Flags);
end;
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads