Advertisement
Guest User

Untitled

a guest
Jul 15th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.ComponentModel;
  7. using System.Collections;
  8.  
  9. namespace LeCombo        // I already had a MyCombo
  10. {
  11.     // show this one in the toolbox
  12.     [ToolboxItem(true)]
  13.     public class myComboBox : mimComboBox
  14.     {
  15.         public myComboBox()
  16.         {
  17.             Items = new object();
  18.             items = new myItems(this);
  19.         }
  20.  
  21.         // keep VS from trying to serialize the old one
  22.         [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  23.         new public object Items { get; set; }  // this hides the real Items
  24.        
  25.         // ToDo: "items" doesnt look anything like a collection to VS even with
  26.         // the attributes.  The Collection editor loads, but nothing is serialized
  27.         // Also the original ComboBox SmartTags are still trying to load the original editor
  28.         // which suprises me; those should be able to be modified with a new UIDesigner
  29.  
  30.         // the real UITypeEditor is internal.  Use the simple string collection
  31.         [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  32.         Localizable(true),
  33.         Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing"),
  34.         MergableProperty(false)]
  35.         public myItems items  {get; set; }
  36.        
  37.         // trying to get serialization to work
  38.         private bool ShouldSerializeitems()
  39.         {
  40.             return items.Count > 0;
  41.         }
  42.  
  43.         private void Resetitems()
  44.         {
  45.             items = new myItems(this);
  46.         }
  47.                
  48.  
  49.         public class myItems // this is the custom Items classwith all necessary methods etc..
  50.         {
  51.             // this doesnt need to be public - VS is serializing it.
  52.             private mimComboBox parentCB;
  53.  
  54.             public myItems(myComboBox parent)
  55.             {
  56.                 parentCB = parent;  // reference to the outer class
  57.             }
  58.  
  59.             // converted to private var
  60.             //public mimComboBox parentCB { get; set; }  // the man-in-the-middle
  61.  
  62.             // all your methods..
  63.             public int Add(object o)  // one example of a custom method
  64.             {
  65.                 // add your item-added event here
  66.                 return parentCB.Items_.Add(o);
  67.             }
  68.  
  69.             // one of many many properties  to provide..
  70.             public int Count { get { return parentCB.Items_.Count; } }
  71.  
  72.         }
  73.  
  74.     }  
  75.  
  76. // hide from toolbox
  77. [ToolboxItem(false)]
  78. public class mimComboBox : ComboBox
  79. {
  80.     public ObjectCollection Items_;
  81.     public mimComboBox()
  82.     {
  83.         Items_ = Items;
  84.     }
  85.  
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement