Form2 Open and Fill in Form1 Panel

A

A-PK

Hey....

How could I set my Form2 boundary or size = Form1's Panel1

meaning that my form2 will open when I click on form1's particular button.
and form2 will fill into Panel1, and if the size of panel changed during run
time, the form2 size will change also.

and I have to set form2 fill and form1's panel.

pls guide
 
B

Brandon Potter

When I did this, not saying it's the technically correct way, but I created
a public property like so in Form 2:

Private szFormSize As New Size
Property FormSize() As Size
Get
Return szSize
End Get
Set(ByVal Value As Size)
szSize = Value
End Set
End Property

So that when Form 1's button is clicked, it will create a new instance of
Form2 (or use an existing one) and set

frm2.FormSize.Height = [height]
frm2.FormSize.Width = [width]

And then use them appropriately in form2's load.

Or you can just access the frm2.Size property that's built in to the form if
that floats your boat.

Brandon
 
A

A-PK

the problem is that my form2 size might change in run time...
depend on the form1 panel size


Brandon Potter said:
When I did this, not saying it's the technically correct way, but I created
a public property like so in Form 2:

Private szFormSize As New Size
Property FormSize() As Size
Get
Return szSize
End Get
Set(ByVal Value As Size)
szSize = Value
End Set
End Property

So that when Form 1's button is clicked, it will create a new instance of
Form2 (or use an existing one) and set

frm2.FormSize.Height = [height]
frm2.FormSize.Width = [width]

And then use them appropriately in form2's load.

Or you can just access the frm2.Size property that's built in to the form if
that floats your boat.

Brandon

A-PK said:
Hey....

How could I set my Form2 boundary or size = Form1's Panel1

meaning that my form2 will open when I click on form1's particular button.
and form2 will fill into Panel1, and if the size of panel changed during run
time, the form2 size will change also.

and I have to set form2 fill and form1's panel.

pls guide
 
B

Brandon Potter

OK, then on Form1, handle the SizeChanged event of the panel...

Private Sub Panel1_SizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.SizeChanged

End Sub

And either include a call to a method to resize the form when Form2's
FormSize property is changed, or expose a public function on Form2 that
Form1 can call with the new size that will do the resize.

FWIW,
Brandon


A-PK said:
the problem is that my form2 size might change in run time...
depend on the form1 panel size


Brandon Potter said:
When I did this, not saying it's the technically correct way, but I created
a public property like so in Form 2:

Private szFormSize As New Size
Property FormSize() As Size
Get
Return szSize
End Get
Set(ByVal Value As Size)
szSize = Value
End Set
End Property

So that when Form 1's button is clicked, it will create a new instance of
Form2 (or use an existing one) and set

frm2.FormSize.Height = [height]
frm2.FormSize.Width = [width]

And then use them appropriately in form2's load.

Or you can just access the frm2.Size property that's built in to the
form
if
that floats your boat.

Brandon

during
run
 
A

A-PK

Hi Brandon,

Perhaps, I am not in the right track now. the more I code on, the heavier my
application is....
I would better to explain what I actually want here in order for you to get
the whole pic and correct me if i was wrong.

Well, actually I am writing a application using VB.Net
my application consist of "Treeview1" on the right panel as menu.
then i insert a splitter between "Treeview1" and "Panel1"
ok so my "Panel1" is on the most right hand size. with DOCK set to "Fill"
already.

so basically program interface is like the following

TreeView1 | Panel1

the | is the splitter, so i can resize it....
able to make "Treeview1" resizable and so "Panel1" does, caus the DOCK
already set to FIll

OK, now i add a new form on my application, named Form2.
I make a sub-menu item under "Treeview1" there.
when I click the sub-menu item, i want to show the Form2.
and want the "Form2" size based on the "Pane1" on "Form1"

and when i move the Splitter, i hope the "Form2" size will change
accordingly to Panel1

i dun know is it the right way to do that. or perhaps i am moving into the
wrong directon.
pls guide me


Brandon Potter said:
OK, then on Form1, handle the SizeChanged event of the panel...

Private Sub Panel1_SizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.SizeChanged

End Sub

And either include a call to a method to resize the form when Form2's
FormSize property is changed, or expose a public function on Form2 that
Form1 can call with the new size that will do the resize.

FWIW,
Brandon


A-PK said:
the problem is that my form2 size might change in run time...
depend on the form1 panel size


Brandon Potter said:
When I did this, not saying it's the technically correct way, but I created
a public property like so in Form 2:

Private szFormSize As New Size
Property FormSize() As Size
Get
Return szSize
End Get
Set(ByVal Value As Size)
szSize = Value
End Set
End Property

So that when Form 1's button is clicked, it will create a new instance of
Form2 (or use an existing one) and set

frm2.FormSize.Height = [height]
frm2.FormSize.Width = [width]

And then use them appropriately in form2's load.

Or you can just access the frm2.Size property that's built in to the
form
if
that floats your boat.

Brandon

Hey....

How could I set my Form2 boundary or size = Form1's Panel1

meaning that my form2 will open when I click on form1's particular button.
and form2 will fill into Panel1, and if the size of panel changed during
run
time, the form2 size will change also.

and I have to set form2 fill and form1's panel.

pls guide
 
D

David Clegg

I do something similar to that (if I understand you correctly). The
trick is to create the form and set it's parent to be a panel that
fills the client area of your main form. I've posted an example from
one of my apps (the codes in C# but you should get the general idea).
Note: The code assumes the form has already been created :-

/// <summary>
/// Shows the passed in form in the client area of
SupervisorFunctionForm.
/// </summary>
/// <param name="form">An instance of the form to show.</param>
private void ShowForm(Form form) {
//Close the current form, if it has been assigned
if (currentForm != null)
currentForm.Close();
form.TopLevel = false;
form.FormBorderStyle = FormBorderStyle.None;
form.Parent = this.pnClient;
form.Dock = DockStyle.Fill;
form.Show();
currentForm = form;
}

HTH

--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com
http://cc.borland.com/codecentral/ccweb.exe/author?authorid=72299

Quality Central. The best way to bug Borland about bugs.
http://qc.borland.com

"Facts are meaningless. You could use facts to prove anything that's
even
remotely true." - Homer Simpson
 
B

Brandon Potter

Ahh,

Thanks for the clarification... Now I see what you're trying to do, and
David's post is spot on.

Good luck,

Brandon

A-PK said:
Hi Brandon,

Perhaps, I am not in the right track now. the more I code on, the heavier my
application is....
I would better to explain what I actually want here in order for you to get
the whole pic and correct me if i was wrong.

Well, actually I am writing a application using VB.Net
my application consist of "Treeview1" on the right panel as menu.
then i insert a splitter between "Treeview1" and "Panel1"
ok so my "Panel1" is on the most right hand size. with DOCK set to "Fill"
already.

so basically program interface is like the following

TreeView1 | Panel1

the | is the splitter, so i can resize it....
able to make "Treeview1" resizable and so "Panel1" does, caus the DOCK
already set to FIll

OK, now i add a new form on my application, named Form2.
I make a sub-menu item under "Treeview1" there.
when I click the sub-menu item, i want to show the Form2.
and want the "Form2" size based on the "Pane1" on "Form1"

and when i move the Splitter, i hope the "Form2" size will change
accordingly to Panel1

i dun know is it the right way to do that. or perhaps i am moving into the
wrong directon.
pls guide me


Brandon Potter said:
OK, then on Form1, handle the SizeChanged event of the panel...

Private Sub Panel1_SizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.SizeChanged

End Sub

And either include a call to a method to resize the form when Form2's
FormSize property is changed, or expose a public function on Form2 that
Form1 can call with the new size that will do the resize.

FWIW,
Brandon


A-PK said:
the problem is that my form2 size might change in run time...
depend on the form1 panel size


When I did this, not saying it's the technically correct way, but I
created
a public property like so in Form 2:

Private szFormSize As New Size
Property FormSize() As Size
Get
Return szSize
End Get
Set(ByVal Value As Size)
szSize = Value
End Set
End Property

So that when Form 1's button is clicked, it will create a new
instance
of
Form2 (or use an existing one) and set

frm2.FormSize.Height = [height]
frm2.FormSize.Width = [width]

And then use them appropriately in form2's load.

Or you can just access the frm2.Size property that's built in to the form
if
that floats your boat.

Brandon

Hey....

How could I set my Form2 boundary or size = Form1's Panel1

meaning that my form2 will open when I click on form1's particular
button.
and form2 will fill into Panel1, and if the size of panel changed during
run
time, the form2 size will change also.

and I have to set form2 fill and form1's panel.

pls guide
 
A

A-PK

Hi David,

Thanks for you help : p
I am able to do that : )

thank you so much......

ok, another problem i face now

i set the Formborderstyle.none.

now, i want to close the form2 without creating a button to trigger the
form2 to close, i want use the default button on form1 at the top right most
corner there, when i click the X button, the form2 will close.

normally you click on Form1 X button, form1 and form2 will close togeter.

now i want

if x button is clicked
if form2 is shown then
form2.close
else
all form close
end if
end if
 
D

David Clegg

A-PK said:
now, i want to close the form2 without creating a button to trigger
the form2 to close, i want use the default button on form1 at the top
right most corner there, when i click the X button, the form2 will
close.

Add something like this to your Form.Closing event. It assumes that you
have a member variable called currentForm, which stores the currently
displayed form (this is also handy for when another selection is made,
so you can close the old form before showing the new one).

private void WinForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e) {
if (currentForm != null) {
e.Cancel = true;
currentForm.Close();
currentForm = null;
}
}

--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com
http://cc.borland.com/codecentral/ccweb.exe/author?authorid=72299

Quality Central. The best way to bug Borland about bugs.
http://qc.borland.com

"Oh, yeah, what are you gonna do? Release the dogs? Or the bees? Or the
dogs with bees in their mouth and when they bark, they shoot bees at
you?" - Homer Simpson
 

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