【问题标题】:C# protected override void "Does not exist in current context"C# 受保护的覆盖无效“当前上下文中不存在”
【发布时间】:2013-04-27 16:59:41
【问题描述】:

我有一个类,在其中我为控件Button 覆盖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();
}

这里是“主题”:

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

【问题讨论】:

  • 只需在 OnPaint() 中将 G 设为局部变量即可。

标签: c# overriding protected


【解决方案1】:

NSButton 不继承 ThemeContainer154。

改变

class NSButton : Control

class NSButton : ThemeContainer154 

【讨论】:

    猜你喜欢
    • 2011-11-29
    • 2018-02-18
    • 1970-01-01
    • 2012-01-31
    • 2013-07-01
    • 2012-06-13
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    相关资源
    最近更新 更多