C# 如何用C语言中的可重用类改进windows窗体工具?

C# 如何用C语言中的可重用类改进windows窗体工具?,c#,winforms,listview,doublebuffered,C#,Winforms,Listview,Doublebuffered,我是编程界的新手,无法理解如何使用这里的答案:Robert Jeppesen public class DoublebufferedListView : System.Windows.Forms.ListView { private Timer m_changeDelayTimer = null; public DoublebufferedListView() : base() { // Set common properties for our listviews

我是编程界的新手,无法理解如何使用这里的答案:Robert Jeppesen

public class DoublebufferedListView : System.Windows.Forms.ListView
{
 private Timer m_changeDelayTimer = null;
 public DoublebufferedListView()
    : base()
 {
    // Set common properties for our listviews
    if (!SystemInformation.TerminalServerSession)
    {
       DoubleBuffered = true;
       SetStyle(ControlStyles.ResizeRedraw, true);
    }
 }

 /// <summary>
 /// Make sure to properly dispose of the timer
 /// </summary>
 /// <param name="disposing"></param>
 protected override void Dispose(bool disposing)
 {
    if (disposing && m_changeDelayTimer != null)
    {
       m_changeDelayTimer.Tick -= ChangeDelayTimerTick;
       m_changeDelayTimer.Dispose();
    }
    base.Dispose(disposing);
 }

 /// <summary>
 /// Hack to avoid lots of unnecessary change events by marshaling with a timer:
 /// https://stackoverflow.com/questions/86793/how-to-avoid-thousands-of-needless-listview-selectedindexchanged-events
 /// </summary>
 /// <param name="e"></param>
 protected override void OnSelectedIndexChanged(EventArgs e)
 {
    if (m_changeDelayTimer == null)
    {
       m_changeDelayTimer = new Timer();
       m_changeDelayTimer.Tick += ChangeDelayTimerTick;
       m_changeDelayTimer.Interval = 40;
    }
    // When a new SelectedIndexChanged event arrives, disable, then enable the
    // timer, effectively resetting it, so that after the last one in a batch
    // arrives, there is at least 40 ms before we react, plenty of time 
    // to wait any other selection events in the same batch.
    m_changeDelayTimer.Enabled = false;
    m_changeDelayTimer.Enabled = true;
 }

 private void ChangeDelayTimerTick(object sender, EventArgs e)
 {
    m_changeDelayTimer.Enabled = false;
    base.OnSelectedIndexChanged(new EventArgs());
 }
}

我试图从谷歌上搜索这个主题的答案,但我无法通过使用的关键词找到正确的文章。希望这里有人能指导我如何将这些被视为“组件”的“类”与windows窗体工具一起使用。

您需要以编程方式添加控件:

var lb = new DoublebufferedListView();
yourForm.Controls.Add(lb);
[visual studio的旧版本]

或者,右键单击工具箱,选择“自定义工具箱”,然后从.NET Framework组件选项卡中,单击浏览并定位控件库DLL,将其添加到工具箱中

[来自msdn的更新版本]

在“工具”菜单上,单击“选择工具箱项”

单击浏览

此时会出现“打开”对话框

在“文件夹”窗格中,选择“我的电脑”以浏览电脑驱动器上安装的项目


单击“确定”。

至少在生成后,您的类必须已经位于项目的工具箱中。确保您的团队在需要新的ListView时使用您的控件。然后将所有现有的ListView控件更改为您的控件。因为它是从ListView派生出来的,所以可以通过用Find replace替换ListView声明和执行代码的构造函数来实现。这是一个很有用的方法,Fabio,thx。工作起来很有魅力。甚至不需要浏览任何东西。当我转到工具->选择工具箱项时,VisualStudio刚刚加载了.NET组件一段时间。按下ok,我的DoublebufferedListView出现在工具箱中。
var lb = new DoublebufferedListView();
yourForm.Controls.Add(lb);