user control resize event fires alot

G

Guest

ive got a user control in vs2003 v1.1, below is the general overview,
hopefully its enough....
my problem is, and im not even sure its a problem, is it appears the resize
event is firing multiple times and im not sure if that behavior is correct or
im causing it. if i set one of the captions on my label to 0 and then
increment it by one in the resize event, when i load the application that has
1 of this meter control on it, the label value goes from 0 to 8 meaning the
resize event fired 8 times. is this right or am i causing this or am i
supposed to have some code in there?
in design time when i lay the control on the form, the increment only goes
to 1 or if i toggle a property i have at runtime which calls the resize
event, it also only increments 1.

public class Meter : System.Windows.Forms.Control
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;


//--------------------------------------------------
Label lblTop=new Label();
Label lblLeft=new Label();
Label lblRight=new Label();
Label lblValue=new Label();
ComboBox cmbSelection=new ComboBox();

.....lot more vars here
//--------------------------------------------------

public Meter()
{
// This call is required by the Windows.Forms Designer.
InitializeComponent();

//build the controls for the meter-location will be handled in the resize
event, we dont care about the location at this point
//meter top
lblTop.Size=new System.Drawing.Size(105,14);
lblTop.Font=new Font("Tahoma", 8, FontStyle.Bold);
lblTop.BackColor=m_captionBackColor;
lblTop.ForeColor=m_captionForeColor;
lblTop.TextAlign=m_captionAlignment;
lblTop.Text=m_caption;
this.Controls.Add(lblTop);
....build the controls
//call the resize event so stuff gets aligned right
this.Size=new System.Drawing.Size(lblTop.Width,height);

protected override void OnResize(EventArgs e)
{
....here i make calls to adjust Location, Size, and Font
 
G

Guest

You're causing a cyclic loop by changing size in the OnResize event.

You shouldn't do that.
 
G

Guest

is there a better place or should i just put in code to exit the method if
its already in the method? if the user changes the size of the control, i
need to modify the size of my controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top