locked
Load data into custom UITypeEditor (Design Mode) RRS feed

  • Question

  • Hi!

    Is it possible to load data, say an xml file, in a custom UITypeEditor? I have made a Custom UI Type Editor and in this the user can change varoius properties. Im thinking to serialize them as an xml file.

    Now i would like to save these properties as a template and load then whenever the user desides to use them again.

     

    All this i want to do i design mode....

    Tuesday, November 1, 2011 9:28 AM

Answers

  • I see.  Now I understand what form.  I guess I should have asked if the editor was modal.  That would have been faster.

    In your form Load event you can read a file and do whatever.

    See http://support.microsoft.com/kb/307548 for sample code on how to read XML, if you need it.


    Jose R. MCP
    • Marked as answer by Tobias_K Wednesday, November 2, 2011 12:02 PM
    Wednesday, November 2, 2011 7:14 AM

All replies

  • UI Type Editors are not components, so they cannot be designed in design time in Visual Studio.  So what do you mean by "design mode"?  Your own version perhaps?
    Jose R. MCP
    Tuesday, November 1, 2011 2:34 PM
  • Well the UITypeEditor loads my form for editing a property so in that form i want to load my templates. Is that at all possible?
    Tuesday, November 1, 2011 7:35 PM
  • In what way does the UITypeEditor loads the form?  And does it do this while working in Visual Studio, or does it do it when your executable runs?  What are the templates you want to load?  How do they look like?  Are they .Net classes?
    Jose R. MCP
    Tuesday, November 1, 2011 8:02 PM
  • http://msdn.microsoft.com/en-us/library/system.drawing.design.uitypeeditor.aspx

    After you developed the custom UITypeEditor, it would be used as a separated assembly, everything is published and compiled.

    It is just like a common library project, so you can define a xml file to store things, then let your editor Form load this xml when it is shown.

    End users can read and modify this xml file, and then used in their project through Visual Studio Designer.


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, November 2, 2011 6:15 AM
  • All this is in design mode, working in Visual Studio 2010

     

    This is my UITypeEditor inherited class:

    public class PointColorEditor: UITypeEditor
        {
           
            IWindowsFormsEditorService editorService = null;
            public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
            {
                return UITypeEditorEditStyle.Modal;
            }
            public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                if (provider != null)
                {
                    editorService =
                        provider.GetService(
                        typeof(IWindowsFormsEditorService))
                        as IWindowsFormsEditorService;
                }
    
                if (editorService != null)
                {
                    PointColorEditorForm selectionControl =
                        new GradientEditorForm(
                        (PointColor)value,
                        editorService);
    
                    editorService.ShowDialog(selectionControl);
    
                    value = selectionControl.editedPointColor;
                                   ((System.Windows.Forms.Control)context.Instance).Invalidate(true);
                    selectionControl.Dispose();
                    selectionControl = null;
                }
                
                return value;
            }
    }
    


    So whenever editing a property that has this code of line:

     [Editor(typeof(PointEditor),typeof(System.Drawing.Design.UITypeEditor))]

    it will display the form PointColorEditorForm for editing the property.

    In that form I want to be able to load some xml data that is kind of templates with already user created PointColors.

    Is this possible? All this is  "while working in Visual Studio, and not when my executable runs."

    Wednesday, November 2, 2011 6:19 AM
  • I see.  Now I understand what form.  I guess I should have asked if the editor was modal.  That would have been faster.

    In your form Load event you can read a file and do whatever.

    See http://support.microsoft.com/kb/307548 for sample code on how to read XML, if you need it.


    Jose R. MCP
    • Marked as answer by Tobias_K Wednesday, November 2, 2011 12:02 PM
    Wednesday, November 2, 2011 7:14 AM
  • Yes, you where right!

    I had som error in my serialization code thats why it didnt work the first 100000 times ;) !

     

    After I sorted that out it works like a charm!

    Wednesday, November 2, 2011 12:03 PM
  • I'm glad to hear that it works.

    Have a nice day!


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, November 2, 2011 1:53 PM