Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using System.Drawing.Graphics.FromHdc() in combobox draw item

19 views
Skip to first unread message

Horst Reichert

unread,
Dec 28, 2006, 5:22:32 AM12/28/06
to
I want to apply special drawing routines using System.Drawing.Graphics
inside a combo box user drawing routine.

procedure TRtDashStylesCombo.DrawItem(Index: Integer; Rect:TRect;
State:TOwnerDrawState);
var Gap: Single; dGr: System.Drawing.Graphics; dPen: System.Drawing.Pen;
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(Rect);
Gap := ItemHeight*0.5;
dGr := System.Drawing.Graphics.FromHdc(IntPtr(Canvas.Handle));
dPen :=
System.Drawing.Pen.Create(System.Drawing.Color.FromArgb(FLineColor));
....

The code woks as expected during firstly drawing the control and dropping
down items. But sometimes especially after clicking other combos and re
entering the user drawn combo it will run into a arithmetic overflow error
caused by the FromHdc creation of the graphics object.
Any idea how to solve this issue?

Regards Horst


Unknown

unread,
Dec 28, 2006, 7:02:49 PM12/28/06
to
On Thu, 28 Dec 2006 11:22:32 +0100, Horst Reichert wrote:

> The code woks as expected during firstly drawing the control and dropping
> down items. But sometimes especially after clicking other combos and re
> entering the user drawn combo it will run into a arithmetic overflow error
> caused by the FromHdc creation of the graphics object.
> Any idea how to solve this issue?

Are you freeing or disposing of the graphics object?

Just out of curious why don't you just use the Canvas API's?

--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com

Horst Reichert

unread,
Dec 29, 2006, 2:58:42 AM12/29/06
to

> Are you freeing or disposing of the graphics object?
The Error occures while creating the object.
I freeandnil() the object on exit of the procedure.

> Just out of curious why don't you just use the Canvas API's?

I need special features like transparency, different dasstyles with
linewidth > 1 etc.

btw. the same error is displayed creating graphic objects with canvas.handle
of TBitmap.

Regards Horst


Unknown

unread,
Dec 29, 2006, 1:26:40 PM12/29/06
to
On Fri, 29 Dec 2006 08:58:42 +0100, Horst Reichert wrote:

> btw. the same error is displayed creating graphic objects with canvas.handle
> of TBitmap.

It sounds like some GD objects are not being released properly.

Horst Reichert

unread,
Dec 30, 2006, 8:22:45 AM12/30/06
to
Solved it:
changed
dGr := System.Drawing.Graphics.FromHdc(IntPtr(Canvas.Handle));
to
dGr := System.Drawing.Graphics.FromHdc(IntPtr(Integer(Canvas.Handle)));

no crashes anymore ;-))


0 new messages