Paint Event - Error
-
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 -
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, Lauralaura1316 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
-
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
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 -
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, LauraWhere 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 )
-
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 -
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, LauraHello, 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