WinForms: an alternative to SplitContainer?

Are there any alternative controls someone might suggest replacing WinForms SplitContainer? I don’t like the way the SplitContainer shows this strange dashed strip when it is selected and when dragged. I want to resize the panels, as the user drags them instead of the mouse and does not show dashed stripes when dragging the splitter. Basically, like the way all panel resizing is done in Windows Explorer on Vista.

This is the dotted thing I'm talking about:

splitter
(source: bhslaughter.com )

+6
source share
5 answers

Write your own UserControl separation container. You just simply drop two panels onto the control (for the left and right panels), and then let the space between them be a splitter. The small logic of MouseDown, MouseMove, and MouseUp in UserControl itself will allow you to easily move the "splitter" left and right, and both panels will correctly block it everywhere, but above the separator, so your logic checks if the mouse if above the splitter is as simple as may be.

It may take a little extra work to get the control to work the way you want it to work in design mode.

+9
source

I found this after I saw your question, so I thought I would share: Frequently Asked Questions about SplitContainer

The second link there exactly indicates what you need to do.

Here is the text from this just in case the connection ever dies.

//1. Use the custom control defined in the SplitContainerNoFocus sample //2. Insert the following code in your project, and attach these events to all of the SplitContainers that you don't want stealing focus. // Temp variable to store a previously focused control private Control focused = null; private void splitContainer_MouseDown(object sender, MouseEventArgs e) { // Get the focused control before the splitter is focused focused = getFocused(this.Controls); } private Control getFocused(Control.ControlCollection controls) { foreach (Control c in controls) { if (c.Focused) { // Return the focused control return c; } else if (c.ContainsFocus) { // If the focus is contained inside a control children // return the child return getFocused(c.Controls); } } // No control on the form has focus return null; } private void splitContainer_MouseUp(object sender, MouseEventArgs e) { // If a previous control had focus if (focused != null) { // Return focus and clear the temp variable for // garbage collection focused.Focus(); focused = null; } } 
+5
source

You cannot mess with SplitContainer at all. One possibility is to completely exclude it if you only use it to resize the control. Instead, you could use mouse events on the control itself. Drop the TreeView onto the form and attach it to the left. Subscribe to MouseDown / Move / Up events and write something like this:

  bool mDragging; private bool onTreeEdge(Point pos) { return pos.X >= treeView1.DisplayRectangle.Right - 3; } private void treeView1_MouseMove(object sender, MouseEventArgs e) { treeView1.Cursor = mDragging || onTreeEdge(e.Location) ? Cursors.VSplit : Cursors.Default; if (mDragging) treeView1.Width = eX; } private void treeView1_MouseDown(object sender, MouseEventArgs e) { mDragging = onTreeEdge(e.Location); if (mDragging) treeView1.Capture = true; } private void treeView1_MouseUp(object sender, MouseEventArgs e) { mDragging = false; } 
+1
source

I needed the same thing and set the following properties:

  splitContainer1.Anchor = (AnchorStyles.Top | AnchorStyles.Left); splitContainer1.Dock = DockStyle.Fill; splitContainer1.IsSplitterFixed = true; 

Hope this helps.

+1
source

Also note the shared container component that comes with the free Krypton toolkit

-1
source

Source: https://habr.com/ru/post/890719/


All Articles