Windows Develop Bookmark and Share   
 index > Windows Forms General > Splitting form horizontally in 4 panels
 

Splitting form horizontally in 4 panels

I want to split form horizontally in 4 pannels(sections). Split container classsplits form in twosections.I can use this class gain to split these two section into 4 sections. But that does not give me result I am looking for.

If some one want to resize one section I am looking for other three sections to resize not just one section.

Is there any way to implement this?

Sam56  Monday, May 12, 2008 9:42 PM

Hi Sam. I'm not sure if you wanted a solution that involved two splitters that were height/size manipulatedthrough code butI came up withan example of it anyhow(for one, it was a fun exercise and, for two, maybe someone else can use it). To make this work you only need to add twosplitter controls to you your form (TopSplitter, BottomSplitter) The code handles the rest of it. You shoud be aware that this example fills the entire form up -- if you need to have other controls on the form you should be able to do this by placing the other controls in panels that are docked to the sides and then place these two splitters in a separate panel (created last of the panels - important) that is set to Dock.Fill. Then you only have to change the code here that applies to the Form events to those of the panel (like cursor, MouseMove, MouseDown, MouseUp)...

4-Panel SplitForm

Public Class Form1

Private SplitHeight As Int32 = 0

Private IsMoving As Boolean = False

Private Const BUFFERHEIGHT As Int32 = 2

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.BackColor = Color.Red

TopSplitter.Orientation = Orientation.Horizontal

BottomSplitter.Orientation = Orientation.Horizontal

TopSplitter.Dock = DockStyle.None

BottomSplitter.Dock = DockStyle.None

TopSplitter.Location = New Point(0, 0)

RedrawSplitters()

TopSplitter.SplitterDistance = TopSplitter.Height / 2

BottomSplitter.SplitterDistance = BottomSplitter.Height / 2

SplitHeight = Me.ClientRectangle.Height / 2

RedrawSplitters()

Dim top As SplitterPanel = TopSplitter.Panel2

Dim bottom As SplitterPanel = BottomSplitter.Panel1

AddHandler top.MouseMove, AddressOf SetPanelCursor

AddHandler Bottom.MouseMove, AddressOf SetPanelCursor

End Sub

Private Sub RedrawSplitters()

TopSplitter.Size = New Size(Me.ClientRectangle.Width, SplitHeight - BUFFERHEIGHT)

BottomSplitter.Location = New Point(0, TopSplitter.Bottom + (BUFFERHEIGHT * 2))

BottomSplitter.Size = New Size(Me.ClientRectangle.Width, ClientRectangle.Height -BottomSplitter.Top)

'You can choose whatever panel height behavior you want here...

End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown

IsMoving = (e.Y >= TopSplitter.Bottom AndAlso e.Y <= BottomSplitter.Top)

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

If e.Y >= TopSplitter.Bottom AndAlso e.Y <= BottomSplitter.Top Then

Cursor = Cursors.HSplit

End If

If IsMoving Then

SplitHeight = e.Y

RedrawSplitters()

End If

End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp

IsMoving = False

End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) HandlesMe.Resize

RedrawSplitters()

End Sub

Private Sub SetPanelCursor(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

Cursor = Cursors.Default

End Sub

End Class

I hope this can be helpful for your project.

-DB

Dig-Boy  Monday, May 12, 2008 11:41 PM

Hi Sam. I'm not sure if you wanted a solution that involved two splitters that were height/size manipulatedthrough code butI came up withan example of it anyhow(for one, it was a fun exercise and, for two, maybe someone else can use it). To make this work you only need to add twosplitter controls to you your form (TopSplitter, BottomSplitter) The code handles the rest of it. You shoud be aware that this example fills the entire form up -- if you need to have other controls on the form you should be able to do this by placing the other controls in panels that are docked to the sides and then place these two splitters in a separate panel (created last of the panels - important) that is set to Dock.Fill. Then you only have to change the code here that applies to the Form events to those of the panel (like cursor, MouseMove, MouseDown, MouseUp)...

4-Panel SplitForm

Public Class Form1

Private SplitHeight As Int32 = 0

Private IsMoving As Boolean = False

Private Const BUFFERHEIGHT As Int32 = 2

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.BackColor = Color.Red

TopSplitter.Orientation = Orientation.Horizontal

BottomSplitter.Orientation = Orientation.Horizontal

TopSplitter.Dock = DockStyle.None

BottomSplitter.Dock = DockStyle.None

TopSplitter.Location = New Point(0, 0)

RedrawSplitters()

TopSplitter.SplitterDistance = TopSplitter.Height / 2

BottomSplitter.SplitterDistance = BottomSplitter.Height / 2

SplitHeight = Me.ClientRectangle.Height / 2

RedrawSplitters()

Dim top As SplitterPanel = TopSplitter.Panel2

Dim bottom As SplitterPanel = BottomSplitter.Panel1

AddHandler top.MouseMove, AddressOf SetPanelCursor

AddHandler Bottom.MouseMove, AddressOf SetPanelCursor

End Sub

Private Sub RedrawSplitters()

TopSplitter.Size = New Size(Me.ClientRectangle.Width, SplitHeight - BUFFERHEIGHT)

BottomSplitter.Location = New Point(0, TopSplitter.Bottom + (BUFFERHEIGHT * 2))

BottomSplitter.Size = New Size(Me.ClientRectangle.Width, ClientRectangle.Height -BottomSplitter.Top)

'You can choose whatever panel height behavior you want here...

End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown

IsMoving = (e.Y >= TopSplitter.Bottom AndAlso e.Y <= BottomSplitter.Top)

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

If e.Y >= TopSplitter.Bottom AndAlso e.Y <= BottomSplitter.Top Then

Cursor = Cursors.HSplit

End If

If IsMoving Then

SplitHeight = e.Y

RedrawSplitters()

End If

End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp

IsMoving = False

End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) HandlesMe.Resize

RedrawSplitters()

End Sub

Private Sub SetPanelCursor(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

Cursor = Cursors.Default

End Sub

End Class

I hope this can be helpful for your project.

-DB

Dig-Boy  Monday, May 12, 2008 11:41 PM

You can use google to search for other answers

Custom Search

More Threads

• Question about putting forms on forms
• coordinates of datagridview cell
• How do I chane the date format? VB.net or VS 2005(VB)
• How To Change The keyboard Language .
• draft fonts in Crystal Report 9 VS .NET?
• Defining a max length for ListViewItem.Text
• Custom UI Control Wrapper causing issues with Visual Studio Designer
• Cursor disappears upon tabbing into WebBrowser control
• RichTextBox not displaying French characters
• setting up smtp in web.config for password recovery control