🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.vcl.components.using.dotnet
5 messages
5 total messages Started by Horst Reichert Thu, 28 Dec 2006 10:22
using System.Drawing.Graphics.FromHdc() in combobox draw item
#212
Author: Horst Reichert
Date: Thu, 28 Dec 2006 10:22
22 lines
1755 bytes
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 
Re: using System.Drawing.Graphics.FromHdc() in combobox draw item
#213
Author: Marc Rohloff TeamB
Date: Fri, 29 Dec 2006 00:02
15 lines
1781 bytes
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
Re: using System.Drawing.Graphics.FromHdc() in combobox draw item
#214
Author: Horst Reichert
Date: Fri, 29 Dec 2006 07:58
13 lines
1452 bytes
> 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 
Re: using System.Drawing.Graphics.FromHdc() in combobox draw item
#215
Author: Marc Rohloff TeamB
Date: Fri, 29 Dec 2006 18:26
10 lines
1611 bytes
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.

-- 
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Re: using System.Drawing.Graphics.FromHdc() in combobox draw item
#216
Author: Horst Reichert
Date: Sat, 30 Dec 2006 13:22
7 lines
1339 bytes
Solved it:
changed
  dGr := System.Drawing.Graphics.FromHdc(IntPtr(Canvas.Handle));
to
  dGr := System.Drawing.Graphics.FromHdc(IntPtr(Integer(Canvas.Handle)));

no crashes anymore ;-)) 
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