C# User Controls - setting default properties

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

    C# User Controls - setting default properties

    I have built a working user control. However, to make it work, I always have
    to set certian properties using the properties sheet for the control when
    using it on other forms. I want to be able to set default values for most
    properties so the control will work as-is without requiring the developer to
    set them.

    I notice in the compment initialization code create when I drop the control
    on a form that all the properties are set to null or other appropriate
    'empty' values. How can I modify the control so these initial values are
    correct?

    Thanks!
  • DalePres

    #2
    Re: C# User Controls - setting default properties

    private bool myBoolProperty = false;

    public bool MyBoolProperty
    {
    get { return myBoolProperty; }
    set { myBoolProperty = value; }
    }

    HTH

    DalePres
    MCAD, MCDBA, MCSE


    "countd4" <countd4@discus sions.microsoft .com> wrote in message
    news:B7670E41-3609-402F-9E9B-74BFA8EC9042@mi crosoft.com...[color=blue]
    >I have built a working user control. However, to make it work, I always
    >have
    > to set certian properties using the properties sheet for the control when
    > using it on other forms. I want to be able to set default values for most
    > properties so the control will work as-is without requiring the developer
    > to
    > set them.
    >
    > I notice in the compment initialization code create when I drop the
    > control
    > on a form that all the properties are set to null or other appropriate
    > 'empty' values. How can I modify the control so these initial values are
    > correct?
    >
    > Thanks![/color]


    Comment

    • countd4

      #3
      Re: C# User Controls - setting default properties


      That is how the properties are implemented. The problem is not that I can't
      see them on the new project. The problem is that they are being assigned null
      values by the IDE. So I am guessing that I'm not doing something correctly in
      the control itself to propagate the "default" values. Here are some code
      snipets from the control.

      public class ProgressControl 1 : System.Windows. Forms.UserContr ol
      {
      private string _spinLocation = "L" ; // 'L'eft or 'R'ight
      private string _pcntLocation = "R" ; // 'L'eft or 'R'ight
      ..
      ..
      }
      ..
      ..
      public ProgressControl 1()
      {
      // This call is required by the Windows.Forms Form Designer.
      InitializeCompo nent();

      // TODO: Add any initialization after the InitComponent call

      }

      ..
      ..
      ..
      public string PBSpinLocation
      {
      get {return _spinLocation;}
      set {_spinLocation = value;}
      }
      public string PBPcntLocation
      {
      get {return _pcntLocation;}
      set {_pcntLocation = value;}
      }
      ..
      ..

      Now here is what the IDE does when I drop this control on a new project form:

      private void InitializeCompo nent()
      {
      ..
      ..
      //
      // progressControl 11
      //
      this.progressCo ntrol11.Accessi bleRole =
      System.Windows. Forms.Accessibl eRole.None;
      this.progressCo ntrol11.BackCol or = System.Drawing. Color.Plum;
      this.progressCo ntrol11.Locatio n = new System.Drawing. Point(24, 8);
      this.progressCo ntrol11.Name = "progressContro l11";
      this.progressCo ntrol11.PBarFil lColor = System.Drawing. Color.Empty;
      this.progressCo ntrol11.PBAutoM ax = false;
      this.progressCo ntrol11.PBPcntB ackColor = System.Drawing. Color.Empty;
      this.progressCo ntrol11.PBPcntD isplay = true;
      this.progressCo ntrol11.PBPcntF ont = null;
      this.progressCo ntrol11.PBPcntF ontColor = System.Drawing. Color.Empty;
      this.progressCo ntrol11.PBPcntL ocation = null;
      this.progressCo ntrol11.PBSpinB ackColor = System.Drawing. Color.Empty;
      this.progressCo ntrol11.PBSpinD isplay = true;
      this.progressCo ntrol11.PBSpinF ont = null;
      this.progressCo ntrol11.PBSpinF ontColor = System.Drawing. Color.Empty;
      this.progressCo ntrol11.PBSpinL ocation = null;
      this.progressCo ntrol11.Size = new System.Drawing. Size(280, 96);
      this.progressCo ntrol11.TabInde x = 0;
      //
      ..
      ..
      ..

      So you see how it forces most of the public properties of the control to
      null or empty states? This is my problem!!!

      HTH!

      Count




      "DalePres" wrote:
      [color=blue]
      > private bool myBoolProperty = false;
      >
      > public bool MyBoolProperty
      > {
      > get { return myBoolProperty; }
      > set { myBoolProperty = value; }
      > }
      >
      > HTH
      >
      > DalePres
      > MCAD, MCDBA, MCSE
      >
      >
      > "countd4" <countd4@discus sions.microsoft .com> wrote in message
      > news:B7670E41-3609-402F-9E9B-74BFA8EC9042@mi crosoft.com...[color=green]
      > >I have built a working user control. However, to make it work, I always
      > >have
      > > to set certian properties using the properties sheet for the control when
      > > using it on other forms. I want to be able to set default values for most
      > > properties so the control will work as-is without requiring the developer
      > > to
      > > set them.
      > >
      > > I notice in the compment initialization code create when I drop the
      > > control
      > > on a form that all the properties are set to null or other appropriate
      > > 'empty' values. How can I modify the control so these initial values are
      > > correct?
      > >
      > > Thanks![/color]
      >
      >
      >[/color]

      Comment

      • DalePres

        #4
        Re: C# User Controls - setting default properties

        What you're looking for is a custom ControDesigner for your control which
        can, among a lot of other things, create the default properties when your
        control is dropped onto a form.

        Look up the System.Windows. Forms.Design.Co ntrolDesigner class and override
        the OnSetComponentD efaults() method.

        HTH

        DalePres
        MCAD, MCDBA, MCSE


        "countd4" <countd4@discus sions.microsoft .com> wrote in message
        news:85D94C6E-E92A-4EB8-B414-D4AB6193DACD@mi crosoft.com...[color=blue]
        >
        > That is how the properties are implemented. The problem is not that I
        > can't
        > see them on the new project. The problem is that they are being assigned
        > null
        > values by the IDE. So I am guessing that I'm not doing something correctly
        > in
        > the control itself to propagate the "default" values. Here are some code
        > snipets from the control.
        >
        > public class ProgressControl 1 : System.Windows. Forms.UserContr ol
        > {
        > private string _spinLocation = "L" ; // 'L'eft or
        > 'R'ight
        > private string _pcntLocation = "R" ; // 'L'eft or
        > 'R'ight
        > .
        > .
        > }
        > .
        > .
        > public ProgressControl 1()
        > {
        > // This call is required by the Windows.Forms Form Designer.
        > InitializeCompo nent();
        >
        > // TODO: Add any initialization after the InitComponent call
        >
        > }
        >
        > .
        > .
        > .
        > public string PBSpinLocation
        > {
        > get {return _spinLocation;}
        > set {_spinLocation = value;}
        > }
        > public string PBPcntLocation
        > {
        > get {return _pcntLocation;}
        > set {_pcntLocation = value;}
        > }
        > .
        > .
        >
        > Now here is what the IDE does when I drop this control on a new project
        > form:
        >
        > private void InitializeCompo nent()
        > {
        > .
        > .
        > //
        > // progressControl 11
        > //
        > this.progressCo ntrol11.Accessi bleRole =
        > System.Windows. Forms.Accessibl eRole.None;
        > this.progressCo ntrol11.BackCol or = System.Drawing. Color.Plum;
        > this.progressCo ntrol11.Locatio n = new System.Drawing. Point(24, 8);
        > this.progressCo ntrol11.Name = "progressContro l11";
        > this.progressCo ntrol11.PBarFil lColor = System.Drawing. Color.Empty;
        > this.progressCo ntrol11.PBAutoM ax = false;
        > this.progressCo ntrol11.PBPcntB ackColor = System.Drawing. Color.Empty;
        > this.progressCo ntrol11.PBPcntD isplay = true;
        > this.progressCo ntrol11.PBPcntF ont = null;
        > this.progressCo ntrol11.PBPcntF ontColor = System.Drawing. Color.Empty;
        > this.progressCo ntrol11.PBPcntL ocation = null;
        > this.progressCo ntrol11.PBSpinB ackColor = System.Drawing. Color.Empty;
        > this.progressCo ntrol11.PBSpinD isplay = true;
        > this.progressCo ntrol11.PBSpinF ont = null;
        > this.progressCo ntrol11.PBSpinF ontColor = System.Drawing. Color.Empty;
        > this.progressCo ntrol11.PBSpinL ocation = null;
        > this.progressCo ntrol11.Size = new System.Drawing. Size(280, 96);
        > this.progressCo ntrol11.TabInde x = 0;
        > //
        > .
        > .
        > .
        >
        > So you see how it forces most of the public properties of the control to
        > null or empty states? This is my problem!!!
        >
        > HTH!
        >
        > Count
        >
        >
        >
        >
        > "DalePres" wrote:
        >[color=green]
        >> private bool myBoolProperty = false;
        >>
        >> public bool MyBoolProperty
        >> {
        >> get { return myBoolProperty; }
        >> set { myBoolProperty = value; }
        >> }
        >>
        >> HTH
        >>
        >> DalePres
        >> MCAD, MCDBA, MCSE
        >>
        >>
        >> "countd4" <countd4@discus sions.microsoft .com> wrote in message
        >> news:B7670E41-3609-402F-9E9B-74BFA8EC9042@mi crosoft.com...[color=darkred]
        >> >I have built a working user control. However, to make it work, I always
        >> >have
        >> > to set certian properties using the properties sheet for the control
        >> > when
        >> > using it on other forms. I want to be able to set default values for
        >> > most
        >> > properties so the control will work as-is without requiring the
        >> > developer
        >> > to
        >> > set them.
        >> >
        >> > I notice in the compment initialization code create when I drop the
        >> > control
        >> > on a form that all the properties are set to null or other appropriate
        >> > 'empty' values. How can I modify the control so these initial values
        >> > are
        >> > correct?
        >> >
        >> > Thanks![/color]
        >>
        >>
        >>[/color][/color]


        Comment

        Working...