locked
Public CreateGraphics RRS feed

  • Question

  • Hello,

    Using C# I am trying to create a CreateGraphics Object that other methods can use. Right now I have it declared in one method becasue I cannot use "this" outside of a method. Here is what I have to create the object. I want to be able to use other methods to dispose of the image that the object draws but when it is not declared outside a method there is no way (That I know of, keep in mind I am still new to this) to access it.

    System.Drawing.Graphics formGraphic = this.CreateGraphics();

    The main thing I am trying to get at is to make other methods that can dispose of the image formGraphic draws. Any help is appreciated.

    David

    Wednesday, March 31, 2010 2:24 AM

Answers

  • Declare the variable as a private field of the form class:

    private Graphics formGraphics;

     

    then in the constructor (or some method) initialize the field variable:

    formGraphics = this.CreateGraphics();

    • Marked as answer by DavidB1000 Wednesday, March 31, 2010 11:50 PM
    Wednesday, March 31, 2010 5:38 AM

All replies

  • Declare the variable as a private field of the form class:

    private Graphics formGraphics;

     

    then in the constructor (or some method) initialize the field variable:

    formGraphics = this.CreateGraphics();

    • Marked as answer by DavidB1000 Wednesday, March 31, 2010 11:50 PM
    Wednesday, March 31, 2010 5:38 AM
  • Took a few minuetes but that did the trick. Thanks a bunch.

    David

    Wednesday, March 31, 2010 11:50 PM