Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Docking a Form in a Panel 1

Status
Not open for further replies.

woogoo

Programmer
Feb 14, 2004
247
GB
Hi, is it possible to dock a borderless form within a panel, I've had various attempts at this but with no success. Any help would be appreciated.

--


woogoo
 
Yup, that's how my app is setup.

I've got a split container with a panel in it
Code:
mySplitContainer.Panel1.Controls.Add(myForm)

-Sometimes the answer to your question is the hack that works
 
Thanks, but I tried that, crashing the application with an exception saying I couldn't do that.

It may make a difference I do not know, but my form is created within a DLL which has a public method to show the form. With this method taking the panel name as a parameter.

Any suggestions.

woogoo
 
In fact this is the error I get:

Top-level control cannot be added to a control.



woogoo
 
How about setting .TopLevel = False?????

There are several examples of the how to do this on this forum.

[vampire][bat]
 
Thanks earthandfire that did the trick, have a *.

--

woogoo
 
Glad to have helped, woogoo, but chrissie1 deserves the credit - he first posted this a few years ago.

[vampire][bat]
 
Guys I'm glad someone has asked this one as I'm having trouble filling a panel with multiple forms of the same class.

The first form fills beautifully, but the rest don't. The following code is abbreviated.
Code:
   Dim FRM as OpenFileForm

   FRM = New OpenFileForm
   FRM.TopLevel = False
   Me.Panel1.Controls.Add(FRM)

   FRM = New OpenFileForm
   FRM.TopLevel = False
   Me.Panel1.Controls.Add(FRM)

Any ideas on this one?
 
You may want to rework this in one of several different ways.

1. change the name of the form variable, so you get a new variable for each form.
2. create a function which does nothing more than "Return New OpenFileForm"
3. if you are only meaning for one of these to be added to the panel, then you may want to create the variable, run you decision logic to set the variable to the correct instance, then only have one line, at the end, to add it to the panel.

you may also want to check and make sure that it in fact is not adding the second form to the list, the form may be "filling" the panel, if it's dock is set to fill.

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Qik3Coder I really appreciate your input on this one, tried a few different methods around your second point (the first isn't an option as the number of forms being addedd is unknown) including trying a return function for a form variable. Other then the first instance (which fills the panel well), subsequent forms seem to 'tile' down the panel with each one moving further down and to the right.

Your last comment is intriguing though, can you explain what you mean by the form 'filling the panel'?
 
"The number of forms being added is unknown"
Calling you on that one, you only have some many lines of code in your function, even if you just number them with an incrementing number, sooner or later you are going to run out of lines of code.

including trying a return function for a form variable.
How many different types of the same form are you trying to create? if it is only one, there is no reason you can't use a separate function to clean up your code.
Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Panel1.Controls.Add(NewForm())
    End Sub

    Private Function NewForm() As frmBypassWindow
        Dim a As New frmBypassWindow()
        Static intX As Integer = 0
        Static IntY As Integer = 0
        a.Top = intX
        a.Left = IntY
        intX += 20
        a.Height = 20
        a.Width = 30
        a.BackColor = Color.White
        a.TopLevel = False
        a.Visible = True
        a.Show()
        Return a
    End Function


subsequent forms seem to 'tile' down the panel with each one moving further down and to the right.
The location of the form in the panel is entirely up to you, based on docking, filling, anchoring, and initial positioning.


can you explain what you mean by the form 'filling the panel'?
A panel has several different sections, which you can choose from for it's docking behavior, top, bottom, left, right, and center, with center completely filling the area not taken by other controls.

HTH




If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top