| View previous topic :: View next topic |
| Author |
Message |
Henley Grandmaster Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 671
|
Posted: Sun Dec 09, 2007 9:24 pm Post subject: C# changing the size of a form other than itself |
|
|
| Code: | | this.Size = new Size(intWidth, intHeight); |
I used that and it works, but when i try to change this to something else so then it changes the size of a different form, it doesnt seem to work.
| Code: | Form1 frmMain = new Form1();
frmMain.Size = new Size(313, 181); |
Can someone tell me what i did wrong?
Edit: C# 2008
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Mon Dec 10, 2007 12:45 am Post subject: |
|
|
To modify the main form I do this
| Code: |
Form1 f = new Form1();
public Form2(Form1 main)
{
f = main;
InitializeComponent();
}
|
And when calling form2, I do this
| Code: |
Form2 f2 = new Form2(this);
|
|
|
| Back to top |
|
 |
richie86 Grandmaster Cheater
Reputation: 0
Joined: 13 Jan 2006 Posts: 664
|
Posted: Mon Dec 10, 2007 8:03 am Post subject: |
|
|
yeah.. pass your form to the child form, you can control your main form though there, even call a function too.
| Code: | | Frm2 frm = new Frm2(this); |
in your frm2 source; write a constructor
| Code: | private frmMain mParent;
public sub new(frmMain frm)
{
mParent = frmMain;
}
|
so you can..
| Code: | mParent.size bla bla
mParent.CallFunction(); |
_________________
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Mon Dec 10, 2007 7:02 pm Post subject: |
|
|
| Is the form part of your project or is it another application's window? The safest way is to use SetWindowPos to set how big your window is and use the SWP_NOMOVE flag so only the size is affected.
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Dec 10, 2007 10:06 pm Post subject: |
|
|
There are a couple branches that you could be going:
| Code: |
spawn it off at a certain size[a]
/
this application -> 2 ways --- modify it in code, without VS [b]
\
modify a currently existing form[c]
/
YOU
\
another application -> Do what the last guy said
|
a:
Create a constructor that takes in your form so you can do something like this:
| Code: |
Form2 myForm = new Form2(new Size(1,2)); //Don't do that, that's REALLY small
myForm.Show();
...
//in your other form
public Form2(Size s)
{
InitializeComponent();
this.Size = s;
}
|
b:
You'll have to go edit InitializeComponent. I don't really have any code, just go in there and find where it sets "this.Size".
c:
I'm not quite sure when this would be useful/needed, but as the people before me said, try spawning it off as a child form.
_________________
|
|
| Back to top |
|
 |
Henley Grandmaster Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 671
|
Posted: Mon Dec 10, 2007 10:53 pm Post subject: |
|
|
I tried these but it's giving me errors.
O well, i'll just put the thing on my main form, so it wont be modified from a different form.
Thanks for helping though
|
|
| Back to top |
|
 |
|