0

我有一个类,我在其中重写OnPaint了控件Button,它给了我一个错误

图形 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();
}

这是“主题”:

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 name 'G' does not exist in the current context
4

1 回答 1

3

NSButton 不继承 ThemeContainer154 。

改变

class NSButton : Control

class NSButton : ThemeContainer154 
于 2013-04-27T17:02:30.183 回答