NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Win Forms Designer Sample

The sample below is a designer for the HelpLabel extender provider control described in the Win Forms Extender Provider Sample. To download the source code, see the Win Forms Quickstart.

        // <doc>
        // <desc>
        // This is a designer for the HelpLabel.  This designer provides
        // design time feedback for the label.  The help label responds
        // to changes in the active control, but these events do not
        // occur at design time.  In order to provide some usable feedback
        // that the control is working the right way, this designer       
        // listens to selection change events and uses those events to         
        // trigger active control changes.

        // </desc>
        // </doc>
        //
        public class HelpLabelDesigner : RichControlDesigner {
        
            //
            // <doc>
            // <desc>
            //  Overrides Dispose.  Here you remove the handler for the 
            //   selection changed  event. With designers, it is critical            
            // that they clean up any events the have attached.  
            // Otherwise, during the course of an editing session many
            // designers may get created and never destroyed.
            // </desc>
            // </doc>
            //
            public override void Dispose() {
                base.Dispose();
            
                ISelectionService ss = 
           (ISelectionService)GetServiceObject(typeof(ISelectionService));
                if (ss != null) {
                  ss.RemoveOnSelectionChanged(new 
                  EventHandler(OnSelectionChanged));
                }
            }
        
            //
            // <doc>
            // <desc>
            // Overrides initialize.  Here you add an event handler to the 
            // selection service. You have to be  careful not to assume                         
            // that the selection service is available.  
            // It is entirely optional that a service is available and you            
            // should always degrade gracefully if a service is not found. 
            // </desc>
            // </doc>
            //
            public override void Initialize(IComponent component) {
                base.Initialize(component);
                
                ISelectionService ss = 
           (ISelectionService)GetServiceObject(typeof(ISelectionService));
                if (ss != null) {
                    ss.AddOnSelectionChanged(new 
                    EventHandler(OnSelectionChanged));
                }
            }
            
            //
            // <doc>
            // <desc>
            //  The handler for the selection change event.               
            // Here you update the active control within
            // the help label.
            // </desc>
            // </doc>
            //
            private void OnSelectionChanged(object sender, EventArgs e) {
            
                ISelectionService ss = (ISelectionService)sender;
                object c = ss.GetPrimarySelection();
                if (c is Control) {
                    HelpLabel helpLabel = (HelpLabel)Component;
                    helpLabel.activeControl = (Control)c;
                    helpLabel.Invalidate();
                }
            }
        }
    }
}