Resizing forms -question

  • Thread starter Zeljko Bilandzija
  • Start date
Z

Zeljko Bilandzija

Hello, can someone help in this?

I have Form1 (Main) and Form 2 (Options), and Form1 is main form, and I want
on Form2 with button (btn800) change size of form1, and always is same size.

Here is click event of my button and i don't know why it can't resize..

Thanks.....

private void btn800_Click(object sender, EventArgs e)

{

frmMain Main = new frmMain();

Main.Size = new Size(800, 600);

this.Close();

}
 
P

Peter Duniho

I have Form1 (Main) and Form 2 (Options), and Form1 is main form, and I
want
on Form2 with button (btn800) change size of form1, and always is same
size.

Here is click event of my button and i don't know why it can't resize...

Which "frmMain" instance do you want to resize? Because, the code you
posted does in fact change the size of *some* instance of "frmMain", but
probably not the one you intend. You're creating a new instance of
"frmMain" every time you execute that method. Those instances are never
shown, but they do in fact get resized.

If you want to resize a previously-existing instance of "frmMain" (for
example, the one that gets created when you start your application), you
need to pass that reference to the options form so that it can access it..
Something like:

class frmOption
{
private frmMain _Main;

public frmOption(frmMain Main)
{
_Main = Main;
}

private void btn800_Click(object sender, EventArgs e)
{
_Main.Size = new Size(800, 600);
Close();
}
}

Pete
 

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