1

我应该通过在我的 WinForms 应用程序中从 ComboBox 派生一个类来创建一个自定义 ComboBox。我以前从未这样做过,也无法从谷歌找到很多好的例子。

我需要派生一个自定义组合框,以便我可以将自定义组合框类型绑定到特定对象。

你能指出我正确的方向吗?

这就是我到目前为止所拥有的。

自定义组合框.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MAPClient {
    class MAPCodeComboBox : ComboBox {

    }
}

我有一些具体的问题:

  1. 我需要重写哪些方法?
  2. 如何在我的 VS2010 设计器模式下使用它?
4

1 回答 1

0

好的,最后我有以下自定义类型绑定的组合框。让我知道我是否做错了什么。

MAPComboBox.cs

using System.Collections.Generic;
using System.Windows.Forms;

namespace MAPClient {
    class MAPComboBox : ComboBox {
        private MAPCodeObjectCollection MAPCodeItemCollection = null;

        new public MAPCodeObjectCollection Items {
            // override
        }

        new public List<MAPCode> DataSource {
            // override
        }

        public MAPCodeComboBox() { }
    }
}

MAPCodeObjectCollection.cs

using System.Windows.Forms;

namespace MAPClient {
    class MAPCodeObjectCollection : ComboBox.ObjectCollection {
        public MAPCodeObjectCollection(ComboBox owner) : base(owner) { }

        new public int Add(object item) {
            // override
        }

        new public void Insert(int index, object item) {
            // override
        }
    }
}
于 2010-09-11T04:48:44.740 回答