Initializing Components

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

    Initializing Components

    Hello All,

    When creating a Windows Forms UserControl, is there any way to tell if its
    container is in the midst of its InitializeCompo nent call, other than setting
    a property?

    For instance, say I have a control called SomeControl that contains some
    properties Property1, Property2, ..., PropertyN. Each of these properties
    may do something time consuming, like accessing a database or updating UI,
    etc. The constructor may set up some default stuff.

    Then, I have a test container that does something like:

    private void InitializeCompo nent()
    {
    this.MySomeCont rol = new SomeControl();

    // Initialize some other stuff
    // |

    //
    // MyUTM
    //
    this.MySomeCont rol.BackColor = System.Drawing. SystemColors.Co ntrol;
    this.MySomeCont rol.Dock = System.Windows. Forms.DockStyle .Fill;
    this.MySomeCont rol.Property1 = "SomeHostNa me";
    this.MySomeCont rol.Property2 = "MyUserName ";
    // more properties
    this.MySomeCont rol.PropertyN = Colors.Red;
    this.MySomeCont rol.Location = new System.Drawing. Point(0, 0);
    this.MySomeCont rol.Name = "SomeContro l";
    this.MySomeCont rol.Size = new System.Drawing. Size(760, 566);
    this.MySomeCont rol.TabIndex = 8;
    }

    Is there any way to prevent the processing of all the properties until the
    test client is done initializing? I don't want to process Property1, then
    Property2, then PropertyN - instead I want to process PropertyN only.

    Thanks,
    pagates
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Initializing Components

    pagates,

    Your control should implement the ISupportInitial ize interface. The
    designer should pick up on this, and make a call to BeginInit and EndInit to
    indicate when batches of properties are being set.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "pagates" <pagates@discus sions.microsoft .com> wrote in message
    news:80AEC722-57D5-4F84-998A-7EB70A409AB4@mi crosoft.com...[color=blue]
    > Hello All,
    >
    > When creating a Windows Forms UserControl, is there any way to tell if its
    > container is in the midst of its InitializeCompo nent call, other than
    > setting
    > a property?
    >
    > For instance, say I have a control called SomeControl that contains some
    > properties Property1, Property2, ..., PropertyN. Each of these properties
    > may do something time consuming, like accessing a database or updating UI,
    > etc. The constructor may set up some default stuff.
    >
    > Then, I have a test container that does something like:
    >
    > private void InitializeCompo nent()
    > {
    > this.MySomeCont rol = new SomeControl();
    >
    > // Initialize some other stuff
    > // |
    >
    > //
    > // MyUTM
    > //
    > this.MySomeCont rol.BackColor = System.Drawing. SystemColors.Co ntrol;
    > this.MySomeCont rol.Dock = System.Windows. Forms.DockStyle .Fill;
    > this.MySomeCont rol.Property1 = "SomeHostNa me";
    > this.MySomeCont rol.Property2 = "MyUserName ";
    > // more properties
    > this.MySomeCont rol.PropertyN = Colors.Red;
    > this.MySomeCont rol.Location = new System.Drawing. Point(0, 0);
    > this.MySomeCont rol.Name = "SomeContro l";
    > this.MySomeCont rol.Size = new System.Drawing. Size(760, 566);
    > this.MySomeCont rol.TabIndex = 8;
    > }
    >
    > Is there any way to prevent the processing of all the properties until the
    > test client is done initializing? I don't want to process Property1, then
    > Property2, then PropertyN - instead I want to process PropertyN only.
    >
    > Thanks,
    > pagates[/color]


    Comment

    • pagates

      #3
      Re: Initializing Components

      Hi Nicholas,

      Thanks for that information.

      Does this work with VS 2003? I've added the implementation, and see the
      events (simply by putting in a MessageBox), but I don't see any changes in
      InitializeCompo nent call that uses this control.

      The control in question is used in another UserControl - does that make a
      difference?

      Thanks,
      Paul

      "Nicholas Paldino [.NET/C# MVP]" wrote:
      [color=blue]
      > pagates,
      >
      > Your control should implement the ISupportInitial ize interface. The
      > designer should pick up on this, and make a call to BeginInit and EndInit to
      > indicate when batches of properties are being set.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "pagates" <pagates@discus sions.microsoft .com> wrote in message
      > news:80AEC722-57D5-4F84-998A-7EB70A409AB4@mi crosoft.com...[color=green]
      > > Hello All,
      > >
      > > When creating a Windows Forms UserControl, is there any way to tell if its
      > > container is in the midst of its InitializeCompo nent call, other than
      > > setting
      > > a property?
      > >
      > > For instance, say I have a control called SomeControl that contains some
      > > properties Property1, Property2, ..., PropertyN. Each of these properties
      > > may do something time consuming, like accessing a database or updating UI,
      > > etc. The constructor may set up some default stuff.
      > >
      > > Then, I have a test container that does something like:
      > >
      > > private void InitializeCompo nent()
      > > {
      > > this.MySomeCont rol = new SomeControl();
      > >
      > > // Initialize some other stuff
      > > // |
      > >
      > > //
      > > // MyUTM
      > > //
      > > this.MySomeCont rol.BackColor = System.Drawing. SystemColors.Co ntrol;
      > > this.MySomeCont rol.Dock = System.Windows. Forms.DockStyle .Fill;
      > > this.MySomeCont rol.Property1 = "SomeHostNa me";
      > > this.MySomeCont rol.Property2 = "MyUserName ";
      > > // more properties
      > > this.MySomeCont rol.PropertyN = Colors.Red;
      > > this.MySomeCont rol.Location = new System.Drawing. Point(0, 0);
      > > this.MySomeCont rol.Name = "SomeContro l";
      > > this.MySomeCont rol.Size = new System.Drawing. Size(760, 566);
      > > this.MySomeCont rol.TabIndex = 8;
      > > }
      > >
      > > Is there any way to prevent the processing of all the properties until the
      > > test client is done initializing? I don't want to process Property1, then
      > > Property2, then PropertyN - instead I want to process PropertyN only.
      > >
      > > Thanks,
      > > pagates[/color]
      >
      >
      >[/color]

      Comment

      • pagates

        #4
        Re: Initializing Components

        Whoops! Never mind - I found the correct calls.

        I was looking for them in the section that initialized the properties of
        that control.

        "I'll learn that .NET stuff yet!"

        Thanks again,
        pagates


        "pagates" wrote:
        [color=blue]
        > Hi Nicholas,
        >
        > Thanks for that information.
        >
        > Does this work with VS 2003? I've added the implementation, and see the
        > events (simply by putting in a MessageBox), but I don't see any changes in
        > InitializeCompo nent call that uses this control.
        >
        > The control in question is used in another UserControl - does that make a
        > difference?
        >
        > Thanks,
        > Paul
        >
        > "Nicholas Paldino [.NET/C# MVP]" wrote:
        >[color=green]
        > > pagates,
        > >
        > > Your control should implement the ISupportInitial ize interface. The
        > > designer should pick up on this, and make a call to BeginInit and EndInit to
        > > indicate when batches of properties are being set.
        > >
        > > Hope this helps.
        > >
        > >
        > > --
        > > - Nicholas Paldino [.NET/C# MVP]
        > > - mvp@spam.guard. caspershouse.co m
        > >
        > > "pagates" <pagates@discus sions.microsoft .com> wrote in message
        > > news:80AEC722-57D5-4F84-998A-7EB70A409AB4@mi crosoft.com...[color=darkred]
        > > > Hello All,
        > > >
        > > > When creating a Windows Forms UserControl, is there any way to tell if its
        > > > container is in the midst of its InitializeCompo nent call, other than
        > > > setting
        > > > a property?
        > > >
        > > > For instance, say I have a control called SomeControl that contains some
        > > > properties Property1, Property2, ..., PropertyN. Each of these properties
        > > > may do something time consuming, like accessing a database or updating UI,
        > > > etc. The constructor may set up some default stuff.
        > > >
        > > > Then, I have a test container that does something like:
        > > >
        > > > private void InitializeCompo nent()
        > > > {
        > > > this.MySomeCont rol = new SomeControl();
        > > >
        > > > // Initialize some other stuff
        > > > // |
        > > >
        > > > //
        > > > // MyUTM
        > > > //
        > > > this.MySomeCont rol.BackColor = System.Drawing. SystemColors.Co ntrol;
        > > > this.MySomeCont rol.Dock = System.Windows. Forms.DockStyle .Fill;
        > > > this.MySomeCont rol.Property1 = "SomeHostNa me";
        > > > this.MySomeCont rol.Property2 = "MyUserName ";
        > > > // more properties
        > > > this.MySomeCont rol.PropertyN = Colors.Red;
        > > > this.MySomeCont rol.Location = new System.Drawing. Point(0, 0);
        > > > this.MySomeCont rol.Name = "SomeContro l";
        > > > this.MySomeCont rol.Size = new System.Drawing. Size(760, 566);
        > > > this.MySomeCont rol.TabIndex = 8;
        > > > }
        > > >
        > > > Is there any way to prevent the processing of all the properties until the
        > > > test client is done initializing? I don't want to process Property1, then
        > > > Property2, then PropertyN - instead I want to process PropertyN only.
        > > >
        > > > Thanks,
        > > > pagates[/color]
        > >
        > >
        > >[/color][/color]

        Comment

        Working...