By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,341 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

problems with user control

P: n/a
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?
Nov 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Jason,

"Jason Winters" <jw******@comcast.net> schreef in bericht
news:yc********************@comcast.com...
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?

Can you post the code for the user control?

TT
Nov 17 '05 #2

P: n/a
using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

namespace Biller

{

/// <summary>

/// Summary description for StoreSelector.

/// </summary>

public class StoreSelector : System.Windows.Forms.UserControl

{

private static int index;

public System.Windows.Forms.ComboBox comboBox1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public StoreSelector()

{

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

InitializeComponent();
// 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 getSelectedStore()

{
return StoresCollection.getStoreAtIndex(index);
}

private void storeList()

{

this.comboBox1.Items.Clear();

ArrayList stores = new ArrayList(StoresCollection.getStores());

Object storesNames = new Object[stores.Count];

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

{

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

}
if(this.comboBox1.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.Dispose();

}

}

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 InitializeComponent()

{

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

this.SuspendLayout();

//

// comboBox1

//

this.comboBox1.ItemHeight = 13;

this.comboBox1.Name = "comboBox1";

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

this.comboBox1.TabIndex = 0;

this.comboBox1.SelectedIndexChanged += new
System.EventHandler(this.comboBox1_SelectedIndexCh anged);

//

// StoreSelector

//

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

this.comboBox1});

this.Name = "StoreSelector";

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

this.Resize += new System.EventHandler(this.StoreSelector_Resize);

this.ResumeLayout(false);

}

#endregion

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs
e)

{

index = this.comboBox1.SelectedIndex;

}

public void addSelectedEvent(System.EventHandler eh)

{

this.comboBox1.SelectedIndexChanged += new System.EventHandler(eh);
}

private void StoreSelector_Resize(object sender, System.EventArgs e)

{

this.comboBox1.Size = this.Size;

}

public void setSelectedIndex(int i)

{

this.comboBox1.SelectedIndex = i;

index = i;

}

}

}
Nov 17 '05 #3

P: n/a
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

Nov 17 '05 #4

P: n/a
Jason,

"Jason Winters" <jw******@comcast.net> schreef in bericht
news:z4********************@comcast.com...
[...]

There is one question: Where does the control disappear?

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

TT.
Nov 17 '05 #5

P: n/a
Another thing I wouldn't do is making that 'index' static. I see no reason
for that.

TT

"Jason Winters" <jw******@comcast.net> schreef in bericht
news:z4********************@comcast.com...
using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

namespace Biller

{

/// <summary>

/// Summary description for StoreSelector.

/// </summary>

public class StoreSelector : System.Windows.Forms.UserControl

{

private static int index;

public System.Windows.Forms.ComboBox comboBox1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public StoreSelector()

{

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

InitializeComponent();
// 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 getSelectedStore()

{
return StoresCollection.getStoreAtIndex(index);
}

private void storeList()

{

this.comboBox1.Items.Clear();

ArrayList stores = new ArrayList(StoresCollection.getStores());

Object storesNames = new Object[stores.Count];

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

{

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

}
if(this.comboBox1.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.Dispose();

}

}

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 InitializeComponent()

{

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

this.SuspendLayout();

//

// comboBox1

//

this.comboBox1.ItemHeight = 13;

this.comboBox1.Name = "comboBox1";

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

this.comboBox1.TabIndex = 0;

this.comboBox1.SelectedIndexChanged += new
System.EventHandler(this.comboBox1_SelectedIndexCh anged);

//

// StoreSelector

//

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

this.comboBox1});

this.Name = "StoreSelector";

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

this.Resize += new System.EventHandler(this.StoreSelector_Resize);

this.ResumeLayout(false);

}

#endregion

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)

{

index = this.comboBox1.SelectedIndex;

}

public void addSelectedEvent(System.EventHandler eh)

{

this.comboBox1.SelectedIndexChanged += new System.EventHandler(eh);
}

private void StoreSelector_Resize(object sender, System.EventArgs e)

{

this.comboBox1.Size = this.Size;

}

public void setSelectedIndex(int i)

{

this.comboBox1.SelectedIndex = i;

index = i;

}

}

}

Nov 17 '05 #6

P: n/a
Index does need to be static to get the effect I need

"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
wrote in message news:bu*********************@phobos.telenet-ops.be...
Another thing I wouldn't do is making that 'index' static. I see no reason
for that.

TT

"Jason Winters" <jw******@comcast.net> schreef in bericht
news:z4********************@comcast.com...
using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

namespace Biller

{

/// <summary>

/// Summary description for StoreSelector.

/// </summary>

public class StoreSelector : System.Windows.Forms.UserControl

{

private static int index;

public System.Windows.Forms.ComboBox comboBox1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public StoreSelector()

{

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

InitializeComponent();
// 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 getSelectedStore()

{
return StoresCollection.getStoreAtIndex(index);
}

private void storeList()

{

this.comboBox1.Items.Clear();

ArrayList stores = new ArrayList(StoresCollection.getStores());

Object storesNames = new Object[stores.Count];

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

{

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

}
if(this.comboBox1.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.Dispose();

}

}

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 InitializeComponent()

{

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

this.SuspendLayout();

//

// comboBox1

//

this.comboBox1.ItemHeight = 13;

this.comboBox1.Name = "comboBox1";

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

this.comboBox1.TabIndex = 0;

this.comboBox1.SelectedIndexChanged += new
System.EventHandler(this.comboBox1_SelectedIndexCh anged);

//

// StoreSelector

//

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

this.comboBox1});

this.Name = "StoreSelector";

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

this.Resize += new System.EventHandler(this.StoreSelector_Resize);

this.ResumeLayout(false);

}

#endregion

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)

{

index = this.comboBox1.SelectedIndex;

}

public void addSelectedEvent(System.EventHandler eh)

{

this.comboBox1.SelectedIndexChanged += new System.EventHandler(eh);
}

private void StoreSelector_Resize(object sender, System.EventArgs e)

{

this.comboBox1.Size = this.Size;

}

public void setSelectedIndex(int i)

{

this.comboBox1.SelectedIndex = i;

index = i;

}

}

}


Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.