problems with user control

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

    problems with user control

    I have implemented a user control in c# .net 2002 but the problem is that
    the control keeps disappearing off of the form for no reason. I am not
    making any changing to the form or the control. It disappears off of all
    the forms that it is on. Any hints why this is happening?


  • TT \(Tom Tempelaere\)

    #2
    Re: problems with user control

    Jason,

    "Jason Winters" <jwinq123@comca st.net> schreef in bericht
    news:ycCdncAVjN iCAunfRVn-sw@comcast.com. ..[color=blue]
    >I have implemented a user control in c# .net 2002 but the problem is that
    >the control keeps disappearing off of the form for no reason. I am not
    >making any changing to the form or the control. It disappears off of all
    >the forms that it is on. Any hints why this is happening?[/color]


    Can you post the code for the user control?

    TT


    Comment

    • Jason Winters

      #3
      Re: problems with user control

      using System;

      using System.Collecti ons;

      using System.Componen tModel;

      using System.Drawing;

      using System.Data;

      using System.Windows. Forms;

      namespace Biller

      {

      /// <summary>

      /// Summary description for StoreSelector.

      /// </summary>

      public class StoreSelector : System.Windows. Forms.UserContr ol

      {

      private static int index;

      public System.Windows. Forms.ComboBox comboBox1;

      /// <summary>

      /// Required designer variable.

      /// </summary>

      private System.Componen tModel.Containe r components = null;

      public StoreSelector()

      {

      // This call is required by the Windows.Forms Form Designer.

      InitializeCompo nent();


      // TODO: Add any initialization after the InitForm call

      }

      public static void setIndex(int i)

      {

      index = i;

      }

      public static int getIndex()

      {

      return index;

      }

      public static Store getSelectedStor e()

      {


      return StoresCollectio n.getStoreAtInd ex(index);


      }

      private void storeList()

      {

      this.comboBox1. Items.Clear();

      ArrayList stores = new ArrayList(Store sCollection.get Stores());

      Object storesNames = new Object[stores.Count];

      for(int x=0; x< stores.Count;x+ +)

      {

      this.comboBox1. Items.Add(((Sto re)stores[x]).storeName);

      }


      if(this.comboBo x1.Items.Count > 0)

      this.comboBox1. SelectedIndex = index;



      }

      public void load()

      {

      try

      {

      this.storeList( );

      this.comboBox1. SelectedIndex = index;

      }

      catch{}

      }



      /// <summary>

      /// Clean up any resources being used.

      /// </summary>

      protected override void Dispose( bool disposing )

      {

      if( disposing )

      {

      if(components != null)

      {

      components.Disp ose();

      }

      }

      base.Dispose( disposing );

      }

      #region Component Designer generated code

      /// <summary>

      /// Required method for Designer support - do not modify

      /// the contents of this method with the code editor.

      /// </summary>

      private void InitializeCompo nent()

      {

      this.comboBox1 = new System.Windows. Forms.ComboBox( );

      this.SuspendLay out();

      //

      // comboBox1

      //

      this.comboBox1. ItemHeight = 13;

      this.comboBox1. Name = "comboBox1" ;

      this.comboBox1. Size = new System.Drawing. Size(176, 21);

      this.comboBox1. TabIndex = 0;

      this.comboBox1. SelectedIndexCh anged += new
      System.EventHan dler(this.combo Box1_SelectedIn dexChanged);

      //

      // StoreSelector

      //

      this.Controls.A ddRange(new System.Windows. Forms.Control[] {

      this.comboBox1} );

      this.Name = "StoreSelector" ;

      this.Size = new System.Drawing. Size(176, 24);

      this.Resize += new System.EventHan dler(this.Store Selector_Resize );

      this.ResumeLayo ut(false);

      }

      #endregion

      private void comboBox1_Selec tedIndexChanged (object sender, System.EventArg s
      e)

      {

      index = this.comboBox1. SelectedIndex;

      }

      public void addSelectedEven t(System.EventH andler eh)

      {

      this.comboBox1. SelectedIndexCh anged += new System.EventHan dler(eh);


      }

      private void StoreSelector_R esize(object sender, System.EventArg s e)

      {

      this.comboBox1. Size = this.Size;

      }

      public void setSelectedInde x(int i)

      {

      this.comboBox1. SelectedIndex = i;

      index = i;

      }

      }



      }


      Comment

      • orekinbck@yahoo.com.au

        #4
        Re: problems with user control

        Hi Jason

        Firstly, I think that the Designer calls the constructor of your user
        control when the designer displays the control. So, if you have any
        errors in your constructor, then the designer will rip the control off
        your form. In a way, the designer is like a moody teenager. It just
        throws its hands in the air and says 'stuff this' !

        I found that my designer settled right down when I did these things:
        (1) Ensured that there is error handling in every user controls
        constructor
        (2) Put the user controls into their own project
        (3) If I was going to change the user controls:
        (a) Close any form that has the user controls on it
        (b) Change the user controls in their own project
        (c) Compile the user controls project
        (d) Re-open any forms that have the user controls on them

        Oh, one other thing I have found - changing from debug to release mode
        (or vice versa) whilst you have a form open that contains user controls
        ..... has caused me problems as well.

        Hope this Helps
        Bill

        Comment

        • TT \(Tom Tempelaere\)

          #5
          Re: problems with user control

          Jason,

          "Jason Winters" <jwinq123@comca st.net> schreef in bericht
          news:z4OdnYd4w6 drPenfRVn-pw@comcast.com. ..
          [...]

          There is one question: Where does the control disappear?

          When you are designing the form, or at run time?

          TT.


          Comment

          • TT \(Tom Tempelaere\)

            #6
            Re: problems with user control

            Another thing I wouldn't do is making that 'index' static. I see no reason
            for that.

            TT

            "Jason Winters" <jwinq123@comca st.net> schreef in bericht
            news:z4OdnYd4w6 drPenfRVn-pw@comcast.com. ..[color=blue]
            > using System;
            >
            > using System.Collecti ons;
            >
            > using System.Componen tModel;
            >
            > using System.Drawing;
            >
            > using System.Data;
            >
            > using System.Windows. Forms;
            >
            > namespace Biller
            >
            > {
            >
            > /// <summary>
            >
            > /// Summary description for StoreSelector.
            >
            > /// </summary>
            >
            > public class StoreSelector : System.Windows. Forms.UserContr ol
            >
            > {
            >
            > private static int index;
            >
            > public System.Windows. Forms.ComboBox comboBox1;
            >
            > /// <summary>
            >
            > /// Required designer variable.
            >
            > /// </summary>
            >
            > private System.Componen tModel.Containe r components = null;
            >
            > public StoreSelector()
            >
            > {
            >
            > // This call is required by the Windows.Forms Form Designer.
            >
            > InitializeCompo nent();
            >
            >
            > // TODO: Add any initialization after the InitForm call
            >
            > }
            >
            > public static void setIndex(int i)
            >
            > {
            >
            > index = i;
            >
            > }
            >
            > public static int getIndex()
            >
            > {
            >
            > return index;
            >
            > }
            >
            > public static Store getSelectedStor e()
            >
            > {
            >
            >
            > return StoresCollectio n.getStoreAtInd ex(index);
            >
            >
            > }
            >
            > private void storeList()
            >
            > {
            >
            > this.comboBox1. Items.Clear();
            >
            > ArrayList stores = new ArrayList(Store sCollection.get Stores());
            >
            > Object storesNames = new Object[stores.Count];
            >
            > for(int x=0; x< stores.Count;x+ +)
            >
            > {
            >
            > this.comboBox1. Items.Add(((Sto re)stores[x]).storeName);
            >
            > }
            >
            >
            > if(this.comboBo x1.Items.Count > 0)
            >
            > this.comboBox1. SelectedIndex = index;
            >
            >
            >
            > }
            >
            > public void load()
            >
            > {
            >
            > try
            >
            > {
            >
            > this.storeList( );
            >
            > this.comboBox1. SelectedIndex = index;
            >
            > }
            >
            > catch{}
            >
            > }
            >
            >
            >
            > /// <summary>
            >
            > /// Clean up any resources being used.
            >
            > /// </summary>
            >
            > protected override void Dispose( bool disposing )
            >
            > {
            >
            > if( disposing )
            >
            > {
            >
            > if(components != null)
            >
            > {
            >
            > components.Disp ose();
            >
            > }
            >
            > }
            >
            > base.Dispose( disposing );
            >
            > }
            >
            > #region Component Designer generated code
            >
            > /// <summary>
            >
            > /// Required method for Designer support - do not modify
            >
            > /// the contents of this method with the code editor.
            >
            > /// </summary>
            >
            > private void InitializeCompo nent()
            >
            > {
            >
            > this.comboBox1 = new System.Windows. Forms.ComboBox( );
            >
            > this.SuspendLay out();
            >
            > //
            >
            > // comboBox1
            >
            > //
            >
            > this.comboBox1. ItemHeight = 13;
            >
            > this.comboBox1. Name = "comboBox1" ;
            >
            > this.comboBox1. Size = new System.Drawing. Size(176, 21);
            >
            > this.comboBox1. TabIndex = 0;
            >
            > this.comboBox1. SelectedIndexCh anged += new
            > System.EventHan dler(this.combo Box1_SelectedIn dexChanged);
            >
            > //
            >
            > // StoreSelector
            >
            > //
            >
            > this.Controls.A ddRange(new System.Windows. Forms.Control[] {
            >
            > this.comboBox1} );
            >
            > this.Name = "StoreSelector" ;
            >
            > this.Size = new System.Drawing. Size(176, 24);
            >
            > this.Resize += new System.EventHan dler(this.Store Selector_Resize );
            >
            > this.ResumeLayo ut(false);
            >
            > }
            >
            > #endregion
            >
            > private void comboBox1_Selec tedIndexChanged (object sender,
            > System.EventArg s e)
            >
            > {
            >
            > index = this.comboBox1. SelectedIndex;
            >
            > }
            >
            > public void addSelectedEven t(System.EventH andler eh)
            >
            > {
            >
            > this.comboBox1. SelectedIndexCh anged += new System.EventHan dler(eh);
            >
            >
            > }
            >
            > private void StoreSelector_R esize(object sender, System.EventArg s e)
            >
            > {
            >
            > this.comboBox1. Size = this.Size;
            >
            > }
            >
            > public void setSelectedInde x(int i)
            >
            > {
            >
            > this.comboBox1. SelectedIndex = i;
            >
            > index = i;
            >
            > }
            >
            > }
            >
            >
            >
            > }
            >
            >[/color]


            Comment

            • Jason Winters

              #7
              Re: problems with user control

              Index does need to be static to get the effect I need

              "TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotm ailD.Tcom/\/\@P$_0_/\/>
              wrote in message news:bu5de.7848 3$X62.5092464@p hobos.telenet-ops.be...[color=blue]
              > Another thing I wouldn't do is making that 'index' static. I see no reason
              > for that.
              >
              > TT
              >
              > "Jason Winters" <jwinq123@comca st.net> schreef in bericht
              > news:z4OdnYd4w6 drPenfRVn-pw@comcast.com. ..[color=green]
              >> using System;
              >>
              >> using System.Collecti ons;
              >>
              >> using System.Componen tModel;
              >>
              >> using System.Drawing;
              >>
              >> using System.Data;
              >>
              >> using System.Windows. Forms;
              >>
              >> namespace Biller
              >>
              >> {
              >>
              >> /// <summary>
              >>
              >> /// Summary description for StoreSelector.
              >>
              >> /// </summary>
              >>
              >> public class StoreSelector : System.Windows. Forms.UserContr ol
              >>
              >> {
              >>
              >> private static int index;
              >>
              >> public System.Windows. Forms.ComboBox comboBox1;
              >>
              >> /// <summary>
              >>
              >> /// Required designer variable.
              >>
              >> /// </summary>
              >>
              >> private System.Componen tModel.Containe r components = null;
              >>
              >> public StoreSelector()
              >>
              >> {
              >>
              >> // This call is required by the Windows.Forms Form Designer.
              >>
              >> InitializeCompo nent();
              >>
              >>
              >> // TODO: Add any initialization after the InitForm call
              >>
              >> }
              >>
              >> public static void setIndex(int i)
              >>
              >> {
              >>
              >> index = i;
              >>
              >> }
              >>
              >> public static int getIndex()
              >>
              >> {
              >>
              >> return index;
              >>
              >> }
              >>
              >> public static Store getSelectedStor e()
              >>
              >> {
              >>
              >>
              >> return StoresCollectio n.getStoreAtInd ex(index);
              >>
              >>
              >> }
              >>
              >> private void storeList()
              >>
              >> {
              >>
              >> this.comboBox1. Items.Clear();
              >>
              >> ArrayList stores = new ArrayList(Store sCollection.get Stores());
              >>
              >> Object storesNames = new Object[stores.Count];
              >>
              >> for(int x=0; x< stores.Count;x+ +)
              >>
              >> {
              >>
              >> this.comboBox1. Items.Add(((Sto re)stores[x]).storeName);
              >>
              >> }
              >>
              >>
              >> if(this.comboBo x1.Items.Count > 0)
              >>
              >> this.comboBox1. SelectedIndex = index;
              >>
              >>
              >>
              >> }
              >>
              >> public void load()
              >>
              >> {
              >>
              >> try
              >>
              >> {
              >>
              >> this.storeList( );
              >>
              >> this.comboBox1. SelectedIndex = index;
              >>
              >> }
              >>
              >> catch{}
              >>
              >> }
              >>
              >>
              >>
              >> /// <summary>
              >>
              >> /// Clean up any resources being used.
              >>
              >> /// </summary>
              >>
              >> protected override void Dispose( bool disposing )
              >>
              >> {
              >>
              >> if( disposing )
              >>
              >> {
              >>
              >> if(components != null)
              >>
              >> {
              >>
              >> components.Disp ose();
              >>
              >> }
              >>
              >> }
              >>
              >> base.Dispose( disposing );
              >>
              >> }
              >>
              >> #region Component Designer generated code
              >>
              >> /// <summary>
              >>
              >> /// Required method for Designer support - do not modify
              >>
              >> /// the contents of this method with the code editor.
              >>
              >> /// </summary>
              >>
              >> private void InitializeCompo nent()
              >>
              >> {
              >>
              >> this.comboBox1 = new System.Windows. Forms.ComboBox( );
              >>
              >> this.SuspendLay out();
              >>
              >> //
              >>
              >> // comboBox1
              >>
              >> //
              >>
              >> this.comboBox1. ItemHeight = 13;
              >>
              >> this.comboBox1. Name = "comboBox1" ;
              >>
              >> this.comboBox1. Size = new System.Drawing. Size(176, 21);
              >>
              >> this.comboBox1. TabIndex = 0;
              >>
              >> this.comboBox1. SelectedIndexCh anged += new
              >> System.EventHan dler(this.combo Box1_SelectedIn dexChanged);
              >>
              >> //
              >>
              >> // StoreSelector
              >>
              >> //
              >>
              >> this.Controls.A ddRange(new System.Windows. Forms.Control[] {
              >>
              >> this.comboBox1} );
              >>
              >> this.Name = "StoreSelector" ;
              >>
              >> this.Size = new System.Drawing. Size(176, 24);
              >>
              >> this.Resize += new System.EventHan dler(this.Store Selector_Resize );
              >>
              >> this.ResumeLayo ut(false);
              >>
              >> }
              >>
              >> #endregion
              >>
              >> private void comboBox1_Selec tedIndexChanged (object sender,
              >> System.EventArg s e)
              >>
              >> {
              >>
              >> index = this.comboBox1. SelectedIndex;
              >>
              >> }
              >>
              >> public void addSelectedEven t(System.EventH andler eh)
              >>
              >> {
              >>
              >> this.comboBox1. SelectedIndexCh anged += new System.EventHan dler(eh);
              >>
              >>
              >> }
              >>
              >> private void StoreSelector_R esize(object sender, System.EventArg s e)
              >>
              >> {
              >>
              >> this.comboBox1. Size = this.Size;
              >>
              >> }
              >>
              >> public void setSelectedInde x(int i)
              >>
              >> {
              >>
              >> this.comboBox1. SelectedIndex = i;
              >>
              >> index = i;
              >>
              >> }
              >>
              >> }
              >>
              >>
              >>
              >> }
              >>
              >>[/color]
              >
              >[/color]


              Comment

              Working...