SplitContainer Woes

Thesolis

Member
Joined
Apr 22, 2009
Messages
16
Programming Experience
1-3
I'm having a bad day with SplitContainers. This is the first time I've used them in an application, and I've been running into problems nonstop.
My program is set up like this: I have one SplitContainer with a panel and another SplitContainer so that I have 3 windows: One main, bigger window and two smaller windows, all of which need to be adjustable.
Inside each of these windows I will be drawing graphics (using System.Graphics).

Now, the issues:
1. I can't draw in the SplitContainer panels past the dimensions that they had originally. I was trying to draw axis in each of the panels, but the lines would never draw past the original dimensions when the splitter was moved and the panels were resized.
2. I have a sub that handles the SplitterMove event for each SplitContainer, so that the same code is executed whenever either splitter is moved. However, this doesn't seem to be working. When I move the main splitter and redraw, nothing is redrawn in one of the other panels. I can't figure out why because the exact same code produces the results I want when it is executed from a button.

Here's the code I'm using for drawing lines:
VB.NET:
Public Sub Draw_Axis()
        gxy.DrawLine(Pens.Red, 0, PanelCenters(0).Y, spPnl1.Panel1.Width, PanelCenters(0).Y)
        gxy.DrawLine(Pens.Green, PanelCenters(0).X, 0, PanelCenters(0).X, spPnl1.Panel1.Height)

        gxz.DrawLine(Pens.Red, 0, PanelCenters(1).Y, spPnl2.Panel1.Width, PanelCenters(1).Y)
        gxz.DrawLine(Pens.Blue, PanelCenters(1).X, 0, PanelCenters(1).X, spPnl2.Panel1.Height)

        gzy.DrawLine(Pens.Blue, 0, PanelCenters(2).Y, spPnl2.Panel2.Width, PanelCenters(2).Y)
        gzy.DrawLine(Pens.Green, PanelCenters(2).X, 0, PanelCenters(2).X, spPnl2.Panel2.Height)
    End Sub

And here's the code I'm using for calculating the values in the block above:
VB.NET:
 Public Sub Define_Centers()
        'Define the centers of each panel.
        PanelCenters(0).X = spPnl1.Panel1.Width / 2
        PanelCenters(0).Y = spPnl1.Panel1.Height / 2

        PanelCenters(1).X = spPnl2.Panel1.Width / 2
        PanelCenters(1).Y = spPnl2.Panel1.Height / 2

        PanelCenters(2).X = spPnl2.Panel2.Width / 2
        PanelCenters(2).Y = spPnl2.Panel2.Height / 2
    End Sub
 
Call Define_Centers from SplitterMoved event handler. Use each panels Paint event to do the drawing, where you draw using e.Graphics object.
 
Thanks for the response. I've been gone a couple days, but I'm back and I was able to try your solution.
I've migrated the drawing events to panels inside each SplitContainer panel so that I could use the double buffering property of the panel controls.

As for my original problem, I was able to fix the drawing surface size by redefining each graphics object on the paint even.
This solution, however, creates yet more problems. Now I don't always get all 6 lines drawn like I want. Instead, the program will only draw in one or two panels at a time, and it seems to be completely random.
I'm not entirely sure what kind of solution for which I should be looking, but I appreciate the help.
 
Ok, problem solved. What I did was pass the Draw_Axis sub with two ByVal arguments. One for the graphics (e.graphics) and the other for the sender, and then added a Select Case inside the Draw_Axis sub to specify where to draw each pair of lines.
Thanks for the help.
 
Not sure if you managed to use Paint event and Graphics correctly.
In addition if you want to avoid lots of manual refreshes you can set the control style ResizeRedraw for your panels, in their constructor:
Me.SetStyle(ControlStyles.ResizeRedraw, True)

You can also do without the extra Panel layer by using reflection to set the DoubleBuffered property for each panel in SplitterPanel.
 
Back
Top