Custom Windows Control library in C# -


how can implement small task features in own custom windows control library below? alt text

you need create own designer control. start adding reference system.design. sample control this:

using system; using system.windows.forms; using system.componentmodel; using system.componentmodel.design; using system.windows.forms.design;  [designer(typeof(mycontroldesigner))] public class mycontrol : control {     public bool prop { get; set; } } 

note [designer] attribute, sets custom control designer. yours started, derive own designer controldesigner. override actionlists property create task list designer:

internal class mycontroldesigner : controldesigner {     private designeractionlistcollection actionlists;     public override designeractionlistcollection actionlists {         {             if (actionlists == null) {                 actionlists = new designeractionlistcollection();                 actionlists.add(new myactionlistitem(this));             }             return actionlists;         }     } } 

now need create custom actionlistitem, this:

internal class myactionlistitem : designeractionlist {     public myactionlistitem(controldesigner owner)         : base(owner.component) {     }     public override designeractionitemcollection getsortedactionitems() {         var items = new designeractionitemcollection();         items.add(new designeractiontextitem("hello world", "category1"));         items.add(new designeractionpropertyitem("checked", "sample checked item"));         return items;     }     public bool checked {         { return ((mycontrol)base.component).prop; }         set { ((mycontrol)base.component).prop = value; }     } } 

building list in getsortedactionitems method key creating own task item panel.

that's happy version. should note crashed visual studio desktop 3 times while working on example code. vs2008 not resilient unhandled exceptions in custom designer code. save often. debugging design time code requires starting instance of vs can stop debugger on design-time exceptions.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -