Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 141569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:47:51+00:00 2026-05-11T07:47:51+00:00

I’m writing a biorhythm app. To test it i have a form with a

  • 0

I’m writing a biorhythm app. To test it i have a form with a Button and a PictureBox. When I click on the button i do

myPictureBox.Image = GetBiorhythm2(); 

Which runs ok for the first time, but on the second click it causes the following exception:

System.ArgumentException: Parameter is not valid.    at System.Drawing.Graphics.CheckErrorStatus    at System.Drawing.Graphics.FillEllipse    at Larifari.Biorhythm.Biorhythm.GetBiorhythm2 in c:\delo\Horoskop\Biorhythm.cs:line 157    at Larifari.test.Button1Click in c:\delo\Horoskop\test.Designer.cs:line 169    at System.Windows.Forms.Control.OnClick    at System.Windows.Forms.Button.OnClick    at System.Windows.Forms.Button.OnMouseUp    at System.Windows.Forms.Control.WmMouseUp    at System.Windows.Forms.Control.WndProc    at System.Windows.Forms.ButtonBase.WndProc    at System.Windows.Forms.Button.WndProc    at ControlNativeWindow.OnMessage    at ControlNativeWindow.WndProc    at System.Windows.Forms.NativeWindow.DebuggableCallback    at ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop    at ThreadContext.RunMessageLoopInner    at ThreadContext.RunMessageLoop    at System.Windows.Forms.Application.Run    at Larifari.test.Main in c:\delo\Horoskop\test.cs:line 20 

the cut-down function which causes the error is :

public static Image GetBiorhythm2() {         Bitmap bmp = new Bitmap(600, 300);         Image img = bmp;         Graphics g = Graphics.FromImage(img);          Brush brush = Brushes.Black;         g.FillEllipse(brush, 3, 3, 2, 2); //Here the exception is thrown on the second call to the function          brush.Dispose(); //If i comment this out, it works ok.          return img;  } 

if I comment-out the brush disposal it works ok, but I am not happy with that and wish to find an alternative solution. Can you help me please ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:47:52+00:00Added an answer on May 11, 2026 at 7:47 am

    It looks like you’re trying to dispose of a static, which causes some problems next time it’s used:

        Brush brush = Brushes.Black;     g.FillEllipse(brush, 3, 3, 2, 2); //Here the exception is thrown on the second call to the function      brush.Dispose(); //If i comment this out, it works ok. 

    When you set brush = Brushes.Black, you’re actually setting brush as a reference (or pointer) to the static Brushes.Black. By disposing it, you’re effectively writing:

        Brushes.Black.dispose(); 

    When you come back around to use the black brush again, the runtime says you can’t because it’s already been disposed of, and isn’t a valid argument to g.FillEllipse()

    A better way to write this might be just simply:

        g.FillEllipse(Brushes.Black, 3, 3, 2, 2); 

    Or, if you want to be really complex about it:

        Brush brush = Brushes.Black.Clone();     g.FillEllipse( brush, 3, 3, 2, 2 );     brush.Dispose(); 

    Or if you don’t care about things looking wrong, just comment out the brush.Dispose(); line in your original code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.