Search code examples
vb.netwinformsvisual-studiosplitcontainer

WinForms SplitContainer and its spacing and resizing


I seem to have a lot of trouble getting a SplitContainer adjusted the way I like it. I have the following form called frmMain:

frmMain Screenshot

In the form Load code I have to following code:

With MainContainer
    .IsSplitterFixed = True
    .Dock = DockStyle.Fill
    .SplitterDistance = 200
    .FixedPanel = FixedPanel.Panel1
    .Panel1.BackgroundImage = Resources.My.Resources.ResourceFile._001
    .Panel2.BackColor = Color.White
    .Panel2.AutoScroll = True
End With

When I run the code I get the following:

frmMain (Compiled)

I want to remove the gray splitter since there is no use to it. Is this a common beauty bug and is it possible to remove it?

My second problem with the SplitContainer is if I resize my window, the backgroundImage in Panel1 and the white color in Panel2 don't adjust with the window. I searched high and low to the Resize code but I can't find it. The Panel2 has User Controls, eg. Dashboard and are loaded this way: MainContainer.Panel2.Controls.Add(Dashboard).

Is it also possible that Panel2 automatically adjusts to the weidht of the window so thay you only have a hortizontal scrollbar?

Thank you for reading my question and hopefully you can help me solve my problems with the SplitContainer. Have a nice day.


Solution

  • You have 2 options:

    • Use TableLayoutPanel (as @erdomke suggests)
    • Use 2 Panel controls

    For 2 panel controls, dock panel1 to Left, and dock panel2 to Fill. To fill panel2 with a UserControl that resizes, set it's Dock property also to Fill.