Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone,
The content of the codes given below; 3 panels and 2 Splitter are required. However, the 2nd splitter (Green) must be located between the gray and brown panel. But not in the right place. Are there any suggestions? Thanks.

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Show()

        Dim tmpSplitter As Splitter
        Dim tmpPanel As Panel
        Dim MainPanel As Panel

        ' This is main panel
        '
        MainPanel = New Panel
        With MainPanel
            .Name = "MainPanel"
            .Dock = DockStyle.Fill
            .BackColor = Color.LightGray
            .BorderStyle = BorderStyle.Fixed3D
            .Visible = True
        End With
        Me.Controls.Add(MainPanel)

        ' 1: First Top Panel and Splitter 
        '
        tmpPanel = New Panel
        With tmpPanel
            .Name = "Panel1"
            .Dock = DockStyle.Top
            .BackColor = Color.Red
            .Visible = True
        End With

        tmpSplitter = New Splitter
        With tmpSplitter
            .Name = "Split1"
            .Dock = DockStyle.Top
            .BackColor = Color.Blue
            .Cursor = Cursors.HSplit
        End With

        Me.Controls.Add(tmpSplitter)
        Me.Controls.Add(tmpPanel)


        ' 2: Second Panel added to the left side of the main panel
        '
        MainPanel.Dock = DockStyle.Right
        MainPanel.Size = New Size(MainPanel.Width * 0.5, MainPanel.Height)

        Dim btn As New Button
        btn.Size = New Size(10, 50)
        btn.Location = New Point(MainPanel.Location.X - btn.Width, MainPanel.Location.Y)
        Me.Controls.Add(btn)


        tmpPanel = New Panel
        With tmpPanel
            .Size = New Size(10, MainPanel.Height)
            .Location = New Point(MainPanel.Location.X - .Width - 5, MainPanel.Location.Y)
            .Name = "Panel2"
            .Dock = DockStyle.Fill
            .BackColor = Color.Brown
        End With

        ' THIS SPLITTER IS NOT IN THE RIGHT PLACE. Must be between brown and gray panel
        '
        tmpSplitter = New Splitter
        With tmpSplitter
            .Size = New Size(5, MainPanel.Height)
            .Location = New Point(MainPanel.Location.X - .Width, MainPanel.Location.Y)
            .Name = "Split2"
            .Dock = DockStyle.Right
            .BackColor = Color.Green
            .Cursor = Cursors.VSplit
        End With

        Me.Controls.Add(tmpSplitter)
        Me.Controls.Add(tmpPanel)

    End Sub
End Class


What I have tried:

I changed the location of Splitter, but it wasn't meaningless. It can be done manually during the design phase, but it cannot be done with code at run time.
Posted
Updated 19-Feb-19 3:36am
Comments
Richard Deeming 18-Feb-19 9:56am    
Why have you tagged this question as "C#" when it's clearly nothing to do with C#?

Just use a SplitContainer instead of a Splitter and use the Panels that it's already working with. That way, the whole splitter handling is done for you.
 
Share this answer
 
Hi everyone, a little more research and try to solve the solution
Me.Controls.SetChildIndex (tmpSplitter, 0)
is enough to write on the last line. Thank you for your contributions
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900