Setting form size

C

Claire

A couple of questions

I have a progress form, if the form user wants to display an extra line of
text then they call the following

{
frmProgress f = new frmProgress();

f.SetLabel("Hello");

f.ShowDialog();

}

In the form code, I have the following function

public void SetLabel(string Info)

{

label1.Text = Info;

this.Height = this.Height + label1.Height;

//this.Height = 144;

}

form borderstyle is set to FixedDialog.

If I step into the code, this.Height is set to 117 but the visual form
doesn't get taller.

If I use the this.Height = 144 then the visual form does get taller.

Why?
 
N

Nicholas Paldino [.NET/C# MVP]

Claire,

That code doesn't look right to me. If you call SetLabel more than
once, then your form will grow and grow, even though you are replacing the
label text, and not appending to it.

My guess is that it has something to do with the BorderStyle, and that
you might be setting it to a smaller value than what it initially is. Can
you post the code?
 
C

Claire

The following code works

public void SetLabel(string Info)

{

label1.Text = Info;

Height = 144;

}



The following code doesn't work.

int OriginalHeight = 0;



public frmProgress()

{



InitializeComponent();

// Height is 101 when fn called

OriginalHeight = Height;

}

public void SetLabel(string Info)

{

label1.Text = Info;

Height = OriginalHeight + label1.Height;

}
 

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