Beispiel #1
0
        private void SelectionChanged(object sender, EventArgs e)
        {
            // Fish out the custom type descriptor and use it
            SampleCustomTypeDescriptor controlDesc = _customTypeDescriptors[_selection.PrimarySelection] as SampleCustomTypeDescriptor;

            if (controlDesc != null)
            {
                _grid.SelectedObject = controlDesc;
            }
        }
Beispiel #2
0
        public DesignForm(Form originalForm, System.Collections.ObjectModel.Collection <string> propertiesToDesign)
        {
            // Copy parameters to fields
            _originalForm       = originalForm;
            _propertiesToDesign = propertiesToDesign;

            // Create hashtables
            _reparentedControls    = new Hashtable();
            _customTypeDescriptors = new Hashtable();

            // Create the DesignSurface and get the View from it;
            _surface = new DesignSurface(typeof(Form));

            // Setup UI, note, this can't be called until _surface is non-null
            SetupUI();

            // Get the IDesignerHost for the surface
            _host = _surface.GetService(typeof(IDesignerHost)) as IDesignerHost;

            // Get the ISelectionService and hook the SelectionChanged event
            _selection = _surface.GetService(typeof(ISelectionService)) as ISelectionService;

            if (_selection != null)
            {
                _selection.SelectionChanged += new EventHandler(SelectionChanged);
            }

            // Get the rootForm from the IDesignerHost
            Form rootForm = _host.RootComponent as Form;

            if (rootForm != null)
            {
                //  Clone the Form's properties
                CloneControlProperties(_originalForm, rootForm);

                // Now that a customTypeDescriptor is around for the Form, use it
                SampleCustomTypeDescriptor formDesc = _customTypeDescriptors[rootForm] as SampleCustomTypeDescriptor;
                if (formDesc != null)
                {
                    _grid.SelectedObject = formDesc;
                }

                // Clone the controls on the Form
                CloneControlsRecursive(_originalForm.Controls, rootForm);
            }
        }