在继承的类中,我使用基础构造函数,但我不能使用类的成员调用此基础构造函数.
在这个例子中,我有一张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)