Re: Problem with Graphics Class...

From: Sujith Manuel (sujith_at_rarefind.com)
Date: 03/08/04

  • Next message: Chris Taylor: "Re: Drawing String Vertically"
    Date: Mon, 8 Mar 2004 20:11:03 +0530
    
    

    Hello Bob,

    Here's the code that causes exception:
    --------------------------------------------
       System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
       RectangleF rect = new RectangleF(0, 0, width, height);

       System.Drawing.Imaging.Metafile metafile =
    new System.Drawing.Imaging.Metafile(frm.CreateGraphics().GetHdc(), rect,
    System.Drawing.Imaging.MetafileFrameUnit.Pixel);

       System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(metafile);
       g.DrawArc(pen, 0, 0, width, height, startAngle, sweepAngle);
       g.Dispose();
       frm.Dispose();
    -------------------------------------------
    If this code block is called mutiple times, then the exception keeps coming
    for a number of times.

    Thanks in advance,
    Sujith Manuel.

    "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
    news:OyHMP8OBEHA.2308@tk2msftngp13.phx.gbl...
    > Please post the code that causes the exception.
    >
    > --
    > Bob Powell [MVP]
    > Visual C#, System.Drawing
    >
    > Check out February's edition of Well Formed.
    > Non-client drawing, Graphics Transform stack and Flood-Filling
    > http://www.bobpowell.net/currentissue.htm
    >
    > Answer those GDI+ questions with the GDI+ FAQ
    > http://www.bobpowell.net/gdiplus_faq.htm
    >
    > Read my Blog at http://bobpowelldotnet.blogspot.com
    >
    > "Sujith Manuel" <sujith@rarefind.com> wrote in message
    > news:Os92B%23MBEHA.1456@TK2MSFTNGP09.phx.gbl...
    > > Hi All,
    > >
    > > I have a problem with System.Drawing.Graphics class. Whenever I use an
    > > object of graphics class, after it goes out of scope, it's giving me an
    > > exception as follows:
    > >
    > > "An unhandled exception of type 'System.InvalidOperationException'
    > occurred
    > > in system.drawing.dll"
    > > "Additional information: The object is currently in use elsewhere."
    > >
    > > Iam also using Dispose() method of Graphics Class. Anybody knows about
    > this
    > > behavior and because of this it's consuming a lot of memory.
    > >
    > > Thanks in advance,
    > > Sujith Manuel.
    > >
    > >
    >
    >


  • Next message: Chris Taylor: "Re: Drawing String Vertically"

    Relevant Pages

    • Re: Problem with Graphics Class...
      ... Please post the code that causes the exception. ... Graphics Transform stack and Flood-Filling ... "Sujith Manuel" wrote in message ... > Iam also using Disposemethod of Graphics Class. ...
      (microsoft.public.dotnet.framework.drawing)
    • Problem with Graphics Class...
      ... object of graphics class, after it goes out of scope, it's giving me an ... "An unhandled exception of type 'System.InvalidOperationException' occurred ... Iam also using Disposemethod of Graphics Class. ... Sujith Manuel. ...
      (microsoft.public.dotnet.framework.drawing)

    Loading