dynamically loading borderless forms

G

Guest

we have a need to create independent forms and then load them to an area (panel) in the main window depending on the user action. Like the main window is layed out like : tree control, splitter bar, panel
then we load the independent forms into panel1 (unload what was there)..
The following is the code I've come up with.... am I on the right/proper track for this or is there a better way

System.Windows.Forms.Form CurrentForm; // defined in the class declaratio

private void menuItem1_Click(object sender, System.EventArgs e

Form2 FormToLoad
FormToLoad = new Form2()

LoadForm(FormToLoad)


private void menuItem2_Click(object sender, System.EventArgs e

Form3 FormToLoad
FormToLoad = new Form3()

LoadForm(FormToLoad)


private void LoadForm(Form TheForm

Point pp

TheForm.MdiParent = this

TheForm.Dock = System.Windows.Forms.DockStyle.Fill
pp = this.splitter1.Location
pp.X += this.splitter1.Width
TheForm.Location = pp

TheForm.Parent = this.panel1
TheForm.Width = this.panel1.Width
TheForm.Height = this.panel1.Height
TheForm.MaximizeBox = false
TheForm.MinimizeBox = false

if (CurrentForm != null
CurrentForm.Close();

CurrentForm = TheForm
TheForm.Show()
 
D

Dmitriy Lapshin [C# / .NET MVP]

John,

I'd use User Controls instead of Forms. Forms are usually top-level or at
least MDI windows by nature and are not well suited to be hosted within a
panel or another container control.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

John Keenan said:
we have a need to create independent forms and then load them to an area
(panel) in the main window depending on the user action. Like the main
window is layed out like : tree control, splitter bar, panel1
then we load the independent forms into panel1 (unload what was there)...
The following is the code I've come up with.... am I on the right/proper
track for this or is there a better way?
 
G

Guest

what we have is a form that needs to be docked to the main panel1 ... certain forms are loaded depending user action.
These forms can contain many other controls.
So are you suggesting to create a User Control (composite control) instead of a borderless form which is docked to
the main panel1?

Also what kind of problems are you expecting if we do use forms instead of User Control

I just ran into quirk... I have the bordless form docked to a panel on the main window...this works just fine whe
I run it local. But when I run the exact same EXE from a server, the titlebar of the borderless form shows up
I even hard coded it
TheForm.FormBorderStyle = FormBorderStyle.None
but no difference... the titlebar still shows when run from a server (but not local).... bug?
 
D

Dmitriy Lapshin [C# / .NET MVP]

John,
So are you suggesting to create a User Control (composite control) instead
of a borderless form which > is docked to the main panel1?

Yes. Hosting a form within another form is a kind of trickery. Forms are
just not designed to work that way. On the contrary, user (composite)
controls are just for that purposes. You can dock such controls within a
panel by using their Dock property, as you would do with any other control.
I used this approach myself and I like it very much.
Also what kind of problems are you expecting if we do use forms instead of
User Control?

I'm afraid, just something like what you've said below - title bars showing
up, unexpected form behavior etc.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

John Keenan said:
what we have is a form that needs to be docked to the main panel1 ...
certain forms are loaded depending user action.
These forms can contain many other controls.
So are you suggesting to create a User Control (composite control) instead
of a borderless form which is docked to
the main panel1?

Also what kind of problems are you expecting if we do use forms instead of User Control?

I just ran into quirk... I have the bordless form docked to a panel on the
main window...this works just fine when
I run it local. But when I run the exact same EXE from a server, the
titlebar of the borderless form shows up.
I even hard coded it:
TheForm.FormBorderStyle = FormBorderStyle.None;
but no difference... the titlebar still shows when run from a server (but
not local).... bug?
 

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