Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Paint Event - Error

Paint Event - Error

Scheduled Pinned Locked Moved C#
graphicscsharpvisual-studiowinformsregex
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laura1316
    wrote on last edited by
    #1

    Hi All, I am trying to create a paint event for my project. See below for my code. I am getting a whole bunch of errors. I am new to GDI+, so I am not sure what I am doing wrong. I am writing in C# and using Visual Studio 2005. I have declared public Point front; in my global variables. I added the reference to System.Drawing. What am I doing wrong? Please see below for errors and code. Error 10 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 11 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 12 'System.Drawing.Point.x' is inaccessible due to its protection level Error 13 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 14 'System.Drawing.Point.y' is inaccessible due to its protection level Error 15 The best overloaded method match for 'System.Drawing.Graphics.DrawEllipse(System.Drawing.Pen, System.Drawing.RectangleF)' has some invalid arguments Error 16 Argument '1': cannot convert from 'System.Drawing.Brush' to 'System.Drawing.Pen' private static void f1_paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(front, ballsize); front.x = 176; front.y = 717; } Thanks, Laura

    L 1 Reply Last reply
    0
    • L laura1316

      Hi All, I am trying to create a paint event for my project. See below for my code. I am getting a whole bunch of errors. I am new to GDI+, so I am not sure what I am doing wrong. I am writing in C# and using Visual Studio 2005. I have declared public Point front; in my global variables. I added the reference to System.Drawing. What am I doing wrong? Please see below for errors and code. Error 10 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 11 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 12 'System.Drawing.Point.x' is inaccessible due to its protection level Error 13 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 14 'System.Drawing.Point.y' is inaccessible due to its protection level Error 15 The best overloaded method match for 'System.Drawing.Graphics.DrawEllipse(System.Drawing.Pen, System.Drawing.RectangleF)' has some invalid arguments Error 16 Argument '1': cannot convert from 'System.Drawing.Brush' to 'System.Drawing.Pen' private static void f1_paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(front, ballsize); front.x = 176; front.y = 717; } Thanks, Laura

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      laura1316 wrote:

      The best overloaded method match for 'System.Drawing.Graphics.DrawEllipse(

      The code you posted does not contain DrawEllipse(...) However based on the error message you can't pass a Brush when a Pen is required, they are not the same thing.

      led mike

      L 1 Reply Last reply
      0
      • L led mike

        laura1316 wrote:

        The best overloaded method match for 'System.Drawing.Graphics.DrawEllipse(

        The code you posted does not contain DrawEllipse(...) However based on the error message you can't pass a Brush when a Pen is required, they are not the same thing.

        led mike

        L Offline
        L Offline
        laura1316
        wrote on last edited by
        #3

        Oops sorry, here is the code with the draw ellipse function call. That did fiz 2 errors but I still have 5 more errors. Please help! Error 10 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 11 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 12 'System.Drawing.Point.x' is inaccessible due to its protection level Error 13 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 14 'System.Drawing.Point.y' is inaccessible due to its protection level Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(front, ballsize); Pen p = new Pen(Color.Blue, 4); front.x = 176; front.y = 717; g.DrawEllipse(p, r); Thanks, Laura

        C L M 3 Replies Last reply
        0
        • L laura1316

          Oops sorry, here is the code with the draw ellipse function call. That did fiz 2 errors but I still have 5 more errors. Please help! Error 10 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 11 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 12 'System.Drawing.Point.x' is inaccessible due to its protection level Error 13 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 14 'System.Drawing.Point.y' is inaccessible due to its protection level Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(front, ballsize); Pen p = new Pen(Color.Blue, 4); front.x = 176; front.y = 717; g.DrawEllipse(p, r); Thanks, Laura

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Where does 'front' come from ? It's obviously a Point, you can't set the x and y, I think they are private and you can set X and Y.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          1 Reply Last reply
          0
          • L laura1316

            Oops sorry, here is the code with the draw ellipse function call. That did fiz 2 errors but I still have 5 more errors. Please help! Error 10 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 11 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 12 'System.Drawing.Point.x' is inaccessible due to its protection level Error 13 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 14 'System.Drawing.Point.y' is inaccessible due to its protection level Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(front, ballsize); Pen p = new Pen(Color.Blue, 4); front.x = 176; front.y = 717; g.DrawEllipse(p, r); Thanks, Laura

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            10,11 and 13 are all the same problem and you do not seem to have posted the relevant code (again). If you don't improve your postings you will find people will not bother replying. 12 and 14 can be fixed with: front.X = 176; front.Y = 717;

            led mike

            1 Reply Last reply
            0
            • L laura1316

              Oops sorry, here is the code with the draw ellipse function call. That did fiz 2 errors but I still have 5 more errors. Please help! Error 10 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 11 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 12 'System.Drawing.Point.x' is inaccessible due to its protection level Error 13 An object reference is required for the nonstatic field, method, or property 'Triax_ReVamp.Filtered_Tilt.front' Error 14 'System.Drawing.Point.y' is inaccessible due to its protection level Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(front, ballsize); Pen p = new Pen(Color.Blue, 4); front.x = 176; front.y = 717; g.DrawEllipse(p, r); Thanks, Laura

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Hello, Just an info: Make sure that your Pen instance p will be disposed. Specially in the Paint event you will get a lot of Pen instances in your memory (plus: I think pen is also a GDI object, which is shown in the taskmanager) which are not able to get cleaned from the GC. I would recomend a "using" block for your code.

              using(Pen p = new Pen(Color.Blue, 4)
              {
              g.DrawEllipse(p, r);
              }

              All the best, Martin

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups