473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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?
Nov 17 '05 #1
6 1561
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rick Delorme | last post by:
Hi Everyone, I have 2 problems I am currently investigating. I am hopeful that someone out there can help me out. 1. I have a windows user control in the web browser. This control has a...
6
by: George Economos | last post by:
I am trying to display a user control contained within an c++ assembly in internet explorer. When I create an equivalent user control in c#, it displays just fine. Before I get into specifics,...
1
by: Barbara Alderton | last post by:
I have the following scenario: I have a user control that contains a registered menu control. The menu and other information on the user control is specific to the user accessing the site. ...
4
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
0
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
5
by: Paul Bromley | last post by:
Can someone give me a very simple example on how to do this? As an example I have a commaned button in a user control. Once this user control is placed on a form I want to be able to respond in the...
0
by: ElSchepo | last post by:
Hi, Just made a UserControl with three objects (calendar, textbox, button), a public method and property. Nothing fancy; just a 'stupid' User Control. The control appears on my test aspx page....
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.