我使用泛型與ListView控件,其初始類的定義是這樣的:泛型的ListView自定義控制
namespace BaseControlLibrary
{
public partial class CustomListView<T> : System.Windows.Forms.ListView
{
// Custom fields, properties, methods go here
public CustomListView(List<T> data)
{
_columnInfo = new Dictionary<int, string>();
_columnIndex = 0;
_lvwItemComparer = new ListViewItemComparer();
this.ListViewItemSorter = _lvwItemComparer;
InitializeColumnNames();
BindDataToListView(data);
this.Invalidate();
}
}
}
這裏是我的設計師檔案:
partial class CustomListView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
//protected override void Dispose(bool disposing)
//{
// if (disposing && (components != null))
// {
// components.Dispose();
// }
// base.Dispose(disposing);
//}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
// this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
我想要做的就是創建一個Windows控件庫,我已經成功完成,但是當我無法將DLL添加到工具箱時會出現問題。我不確定我爲什麼不能這樣做。我認爲所有Windows窗體控件都實現了IComponent接口,這是將項目添加到工具箱的要求。是否因爲類型參數是類定義的一部分?
也許缺少一個公共無參數構造函數? – Zyphrax 2009-08-03 19:28:50