Tgy*_*gys 5 c# toolbox visual-studio-2010 visual-c++
我已经基于Picturebox创建了一个自定义控件:
public class Timebar : System.Windows.Forms.PictureBox
Run Code Online (Sandbox Code Playgroud)
如果我在Form的初始化方法中手动创建控件/设置所有值等,这可以正常工作.
现在我也在工具箱的顶部找到了这个:http://i.imgur.com/4KUc0.png
当我尝试通过msvc插入它时,我得到一个错误.
Failed to create component 'Timebar'. The error message follows:
'System.MissingMethodException: Constructor on type 'SC.Timebar' not found.
Run Code Online (Sandbox Code Playgroud)
这对我的组件Timebar来说并不是一个大问题(因为我将手动添加该组件),但它是我想要制作的自定义Button类(比默认值更奇特).
这个类中有一个构造函数:
public Timebar(Data refr)
{
this._refr = refr;
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决上述错误?
谢谢,
~sgys
设计器中使用的控件必须具有无参数构造函数.设计者需要创建一个控件来显示并允许你操作它,但它不知道如何调用需要参数的构造函数.
那么,我要做的是创建一个无参数的构造函数,它使用默认值链接其他构造函数,即
class Foo
{
public Foo() : this(SomeType.Value) { }
public Foo(SomeType whatever) : { /* do stuff /* }
}
Run Code Online (Sandbox Code Playgroud)