none
User control-Design time support

    Pertanyaan

  • i have created a user control

    and for this control one property is an object of a class named ControlProperties

     

    i have designed a form to accept certain values( essentily the controlproperty class object  ) which are added to an hash list for design time support..my problem is i dont know how to assign perssist this object...i am getting this object during design time..but once i run this the object becomes null..i figured out that the object properties is not being included in the  intialize compnent method.. here is what id did..to open the form during design time

     

    public class DesignSupport : UITypeEditor

    {

    public DesignSupport()

    {

    //

    // TODO: Add constructor logic here

    //

    }

    public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)

    {

    return UITypeEditorEditStyle.Modal;

    }

    public override object EditValue(System.ComponentModel.ITypeDescriptorContext context

    , IServiceProvider provider, object value)

    {

    //use IWindowsFormsEditorService object to display a control in the dropdown area

    IWindowsFormsEditorService frmsvr = (IWindowsFormsEditorService)provider.GetService

    (typeof(IWindowsFormsEditorService));

    if(frmsvr == null)

    return null;

    frmDesigner AForm = new frmDesigner((ControlProperties)value);

    frmsvr.ShowDialog(AForm);

    return AForm.ControlProperty;

    }

    }

     

     

    frmDesigner is the form that is opened to receive data

    13 Agustus 2006 12:32

Semua Balasan

  • Moved to Windows Forms Designer forum.
    13 Agustus 2006 13:09
  • Hello,

    I'm betting your problem is that you are returning the propery of your form directly. This has two problems but the main one is that your form falls out of scope when the method returns and as a result your your property is null.

    To fix this, do the following.

    1. Take out the everything after where you check to see if frmsvr==null) return null; and replace it with something like the following.

    frmDesigner AForm = new frmDesigner((ControlProperties)value);

    if(frmsvr.ShowDialog(AForm) == DialogResult.Ok) //check your dialog result or you may still get a null

    {

    ControlProperties cp = new ControlProperties(AForm.ControlProperty); //SEE COMMENT BELOW

    return base.EditValue(context, provider, (object)cp)

    }

    return base.EditValue(context, provider, value); // just return what was passed in because cancel was pressed.

     

    COMMENT: This line needs to create a new one of your objects that is a copy of the one in your form and return that. If not your form falls out of scope and its property is null. This code is obviously not correct because I don't know your class, but you should get the point.

    Hope this helps.

    Ken

     

     

    14 Agustus 2006 17:56
  • that didnt solve my prob.... the detaiks of my class is not getting written into initialize components..

     

    15 Agustus 2006 9:47
  • I misread your orginal post. If you are wanting to make sure the values you set to your property are persisted (which you did say sorry) then you have to make sure that the designer knows to persist it.

     

    Joey Calisay just posted this in another post that might help you. Look at the DesignerSerializationVisibility attribute in help. When this is set, the designer will know you want it persisted.

     

    Ken

    15 Agustus 2006 14:19
  • yep, you need to aply [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] for your collection property.
    16 Agustus 2006 5:19
  • [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

    i did that...already..:-(

    its something else

     

    i tried both content and visible property do i have to tell the complier what should be written in the initialize component for my component..if so where ?

    i think some thing more has to be done when we are dealing with class objects instead of primitive datatypes

    17 Agustus 2006 12:43
  • can we see the construct for your property? since it is a hashtable, as you say it, it already implements ICollection so it will also use the default CollectionCodeDomSerializer
    17 Agustus 2006 13:09
  •  

     

    not sure if you have solution.  It sounds similar to something I wanted to do recently - collect design time data via a UI Editor, stash it away for subsequent use.  But preferably not in code as that would probably result in in being included in the shippable product, and I had need requirement to rflect on the data at execution time.

    What I have done is to implement two methods in the class in which the data resides -- public void Secure() and public void Restore().  They use the XmlSerializer class to respectively write and read their current object to disk.  In addition there's a static method that given the key data returns the LinkedList that represents the guts of the data.

    The datastore is a single file with multiple named streams (ADS's), so it won't run on non NTFS file systems.  The stream name is constructed from the three properties that identify the object  

    Type         clientClass; 

    MemberTypes  memberType;

        catAction    action;

    These are ToString()'d and dotted together so you end up with something like "Sausage.Method.Remove" as the stream name, it resides in a file that I call the DesignVault, it's path is stashed in properties.settings.  I've written a utility that allows one to examine the vault and do primitive maintenance - ie extract, inject and delete.

    if your interested my profile has a mangled email address, that I'm sure you can straighten.  Drop me a mail and I'll send the code.  I'm not someone who looks at email every day so it might take a few days to get back to you.  I'm examining OnSerialize as an alternative way to trigger things.  Oh I set the serialisation attribute on the properties in question to .Hidden to stop the IDE trying to persist the data structures in question, the very idea of representing an instance of linked list or a hashtable in code gives me the creeps.

    cheers phild

    25 Agustus 2006 1:50