我有一个类,我为控件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
答案 0 :(得分:3)
NSButton不继承ThemeContainer154。
更改
class NSButton : Control
到
class NSButton : ThemeContainer154