How to write the code automaticly into the InitializeComponent?

I make some component and controls in the my toolbox

when I drag them to the form, i hope VS can write the code into the InitializeComponent automaticlly,just like I drag a VS button in the form.

How to archieve this

pls give me some idea

Thanks




Answer this question

How to write the code automaticly into the InitializeComponent?

  • Wuchihchung

    sorry, was about to leave, just post your inquiries here...


  • bugmenot

    how to write DesignerSerializer

    pls give me a example



  • anderl

    namespace Phone_Number_Control

    {

    public class PhoneTypeConverter : TypeConverter

    {

    public PhoneTypeConverter()

    {

    }

    public override bool GetPropertiesSupported(ITypeDescriptorContext context)

    {

    return true;

    }

    public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)

    {

    return TypeDescriptor.GetProperties(typeof(PhoneNumber));

    }

    }

    }



  • Codewarrior3

    seems pretty advanced since he already uses typeconverters and uitypeeditors, please elaborate more on what you need, if you want articles on the serializer thingy, i recommend shawn burke's controlled code generation found in msdn.


  • Shane Griggs - MSFT

    I use the TyeConverter and UITypeEditor

    to display the property in the window

    i want the code can created in code window too



  • Olivertech

    Normally, non-default properties are the ones serialized in the InitializeComponent method block. If you want to create custom method calls, you'd have to attach a custom DesignerSerializer for your control/component.


  • Durone

    pls leave your msn or email,so we can chat conveniently.

    Thanks



  • dnelson

    Maybe I misunderstood the question. But create a custom control and add for example the following code:

    private string test = "muh";

    public string Test
    {
    get { return this.test; }
    set { this.test = value; }
    }

    Compile the solution and add the control to a Form. Now have a look into the InitializeComponent Block and you will find the Test property. I think this was meant.



  • Dijkstra30

    VS sets the properties of you custom control as it does it with the built-in .net controls. They are added if the properties have a default value or if you change a property within the property window.

    Best wishes


  • How to write the code automaticly into the InitializeComponent?