C# C“受保护的覆盖无效”;在当前上下文中不存在”;

C# C“受保护的覆盖无效”;在当前上下文中不存在”;,c#,overriding,protected,C#,Overriding,Protected,我有一个类,在这个类中,我重写了控件按钮的OnPaint,它给了我一个错误 图形G在当前上下文中不存在 但我定义了图形G abstract class ThemeContainer154 : Control { #region " Initialization " protected Graphics G; protected Bitmap B; public ThemeContainer154() { SetStyle((ControlStyles)139270, t

我有一个类,在这个类中,我重写了控件
按钮的
OnPaint
,它给了我一个错误

图形G在当前上下文中不存在

但我定义了图形G

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();
}
这就是“主题”:

我得到的错误是:

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

NSButton不继承ThemeContainer 154

改变

class NSButton : Control


NSButton不继承ThemeContainer 154

改变

class NSButton : Control


只需将
G
设置为OnPaint()中的局部变量。只需将
G
设置为OnPaint()中的局部变量。
class NSButton : ThemeContainer154