相关疑难解决方法(0)

关键字'this'(Me)无法调用基础构造函数

在继承的类中,我使用基础构造函数,但我不能使用类的成员调用此基础构造函数.

在这个例子中,我有一张PicturedLabel,它知道自己的颜色并有一个图像.A TypedLabel : PictureLabel知道它的类型但使用基色.

使用TypedLabel的(基础)图像应使用(基色)颜色着色,但是,我无法获得此颜色

错误:关键字"this"在当前上下文中不可用

解决方法?

/// base class
public class PicturedLabel : Label
{
    PictureBox pb = new PictureBox();
    public Color LabelColor;

    public PicturedLabel()
    {
        // initialised here in a specific way
        LabelColor = Color.Red;
    }

    public PicturedLabel(Image img)
        : base()
    {
        pb.Image = img;
        this.Controls.Add(pb);
    }
}

public enum LabelType { A, B }

/// derived class
public class TypedLabel : PicturedLabel
{
    public TypedLabel(LabelType type)
        : base(GetImageFromType(type, this.LabelColor))
    //Error: Keyword 'this' is not available …
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net oop

4
推荐指数
2
解决办法
5166
查看次数

标签 统计

.net ×1

c# ×1

oop ×1

vb.net ×1