سؤال

من المفترض أن أقوم بإنشاء comboBox مخصص عن طريق استخلاص فصل من Combobox في تطبيق WinForms الخاص بي. لم أفعل هذا من قبل ولم أتمكن من العثور على العديد من مثال جيد من Google.

أنا مطلوب من استخلاص combobox مخصص حتى أتمكن من جعل نوع combobox المخصص محصورة لكائن معين.

هل يمكن أن توجهني إلى الاتجاه الصحيح؟

هذا ما لدي حتى الآن.

CustomCombobox.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 الخاص بي؟
هل كانت مفيدة؟

المحلول

حسنًا ، أخيرًا لدي ما يلي للحصول على comboBox المخصصة. اسمحوا لي أن أعرف إذا كنت أفعل شيئًا خاطئًا.

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
        }
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top