ControlDesigner for custom control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mohit

    #1

    ControlDesigner for custom control

    Hello,

    I am making a custom control which places some restrictions on the
    value of Text property of the control.
    While debugging i noticed that when the control is drag-dropped on a
    form during Design Time, the InitializeNewCo mponent method of the
    ControlDesigner is invoked. After this the text property of my control
    is set to the control name, which Visual Studio automatically assigns(
    name of the control object like textBox1 ...).

    Now if I want a default blank value in the control's text property i
    can set my own designer, override the InitializeNewCo mponent method and
    set the text value after i call the base InitializeNewCo mponent method

    public override void InitializeNewCo mponent(IDictio nary defaultValues)
    {
    base.Initialize NewComponent(de faultValues);
    //over here text property is smthing like MyControl1 or
    MyControl2
    MyControl control1 =this.Component as MyControl ;
    control1.Text = "";
    }

    My question is why is this happening ??

    Even in Microsofts controls like TextBox when I drag the control on the
    form during designtime the text property is set to the control's
    instance name and then immediately(wit hin milli seconds) cleared.

    Thanks and Regards,
    Mohit

  • chanmm

    #2
    Re: ControlDesigner for custom control

    I did play with Customer User Control for textbox but when I drag to the
    form it is blank in my textbox though.

    chanmm



    "mohit" <mohitbhatt79@g mail.comwrote in message
    news:1160821042 .434216.266750@ h48g2000cwc.goo glegroups.com.. .
    Hello,
    >
    I am making a custom control which places some restrictions on the
    value of Text property of the control.
    While debugging i noticed that when the control is drag-dropped on a
    form during Design Time, the InitializeNewCo mponent method of the
    ControlDesigner is invoked. After this the text property of my control
    is set to the control name, which Visual Studio automatically assigns(
    name of the control object like textBox1 ...).
    >
    Now if I want a default blank value in the control's text property i
    can set my own designer, override the InitializeNewCo mponent method and
    set the text value after i call the base InitializeNewCo mponent method
    >
    public override void InitializeNewCo mponent(IDictio nary defaultValues)
    {
    base.Initialize NewComponent(de faultValues);
    //over here text property is smthing like MyControl1 or
    MyControl2
    MyControl control1 =this.Component as MyControl ;
    control1.Text = "";
    }
    >
    My question is why is this happening ??
    >
    Even in Microsofts controls like TextBox when I drag the control on the
    form during designtime the text property is set to the control's
    instance name and then immediately(wit hin milli seconds) cleared.
    >
    Thanks and Regards,
    Mohit
    >

    Comment

    • mohit

      #3
      Re: ControlDesigner for custom control


      chanmm wrote:
      I did play with Customer User Control for textbox but when I drag to the
      form it is blank in my textbox though.
      >
      chanmm
      Hello chanmm ,
      If you override the Text property and debug it you will notice that the
      text property is set to control name and then to string.Empty. The end
      result is a blank value but before that the control name is set. You
      may notice it in the designer as a brief flicker just when you drop the
      control on the form.

      Anyways thanks for responding.
      If I do find some lead on this i will post it here.

      thanks and regards,
      mohit

      Comment

      Working...