简体   繁体   中英

C# protected override void “Does not exist in current context”

I have a class in which I override OnPaint for the control Button , and it gives me an error that

Graphics G does not exist in current context

yet I have Graphics G defined.

abstract class ThemeContainer154 : Control
{
   #region " Initialization "
   protected Graphics G;
   protected Bitmap B;

public ThemeContainer154()
{
   SetStyle((ControlStyles)139270, true);

   _ImageSize = Size.Empty;
   Font = new Font("Verdana", 8);

   MeasureBitmap = new Bitmap(1, 1);
   MeasureGraphics = Graphics.FromImage(MeasureBitmap);

   DrawRadialPath = new GraphicsPath();

   InvalidateCustimization();
}

And here is the "Theme":

class NSButton : Control
{
   protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
   {
      G = e.Graphics;
  G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
      G.Clear(BackColor);
  G.SmoothingMode = SmoothingMode.AntiAlias;
   }
}

The errors I get are:

 The name 'G' does not exist in the current context

The NSButton does not inherit the ThemeContainer154 .

Change

class NSButton : Control

to

class NSButton : ThemeContainer154 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM