2013-04-27 92 views
0

我有我重写OnPaint的控制Button一类“没有在当前的背景下存在”,它给我,C#保护覆盖无效

图形G不会在当前的背景下存在的错误

但我有Graphics 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 
+1

只是要'G'在OnPaint中一个局部变量()。 – 2013-04-27 17:09:41

回答

3

的NSButton不会继承ThemeContainer154。

变化

class NSButton : Control 

class NSButton : ThemeContainer154