![](/img/trans.png)
[英]how to create custom control in visual studio 2015 and add it to toolbox
[英]How to add a custom control to the toolbox?
我已經基於Picturebox創建了一個自定義控件:
public class Timebar : System.Windows.Forms.PictureBox
如果我在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.
這對我的組件Timebar來說並不是一個大問題(因為我將手動添加該組件),但它是我想要制作的自定義Button類(比默認值更奇特)。
這個類中有一個構造函數:
public Timebar(Data refr)
{
this._refr = refr;
}
我該如何解決上述錯誤?
謝謝,
~sgys
設計器中使用的控件必須具有無參數構造函數。 設計者需要創建一個控件來顯示並允許你操作它,但它不知道如何調用需要參數的構造函數。
那么,我要做的是創建一個無參數的構造函數,它使用默認值鏈接其他構造函數,即
class Foo
{
public Foo() : this(SomeType.Value) { }
public Foo(SomeType whatever) : { /* do stuff /* }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.