0% found this document useful (0 votes)
141 views3 pages

Split Container FAQ

This document contains frequently asked questions about the SplitContainer control in .NET. It discusses how to select the SplitContainer at design time, why the splitter may not be visible at runtime, and how to prevent the SplitContainer from stealing focus when the splitter is moved. It also provides code samples to continuously update the SplitContainer's contents while dragging the splitter.

Uploaded by

thefriend
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views3 pages

Split Container FAQ

This document contains frequently asked questions about the SplitContainer control in .NET. It discusses how to select the SplitContainer at design time, why the splitter may not be visible at runtime, and how to prevent the SplitContainer from stealing focus when the splitter is moved. It also provides code samples to continuously update the SplitContainer's contents while dragging the splitter.

Uploaded by

thefriend
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

SplitContainer FAQ

Note: For more information, see http://msdn2.microsoft.com/en-us/library/hb802c99


....................................................... How do I select the SplitContainer at design time? ............................................... Why isnt the splitter visible when I run my application? .......................................... How can I prevent the SplitContainer from stealing focus? ........How can I make the SplitContainer continuously update its contents while the splitter is moving?

How do I select the SplitContainer at design time?


If you want to select a SplitContainer control at design time, click on the splitter. If you click on either of the SplitContainerPanels, you will select them instead. Also you can use the drop down menu in the property grid to select the SplitContainer by name. Finally you can use the Document Outline to select the SplitContainer and control the Z-order of the controls within it.

Why isnt the splitter visible when I run my application?


If the splitter is not distinguishable from the rest of the split container, it is due to the SplitContainerPanels having the same background color as the splitter, and the BorderStyle being set to None. To make the splitter easily recognizable, change the BackColor for the SplitContainerPanels, or set the SplitContainers BorderStyle.

How can I prevent the SplitContainer from stealing focus?


The default behavior for the splitter is to take focus once selected. If you want the splitter to be movable without taking focus you can do one of two things: 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 dont 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) {

} // No control on the form has focus return null; }

if (c.Focused) { // Return the focused control return c; } else if (c.ContainsFocus) { // If the focus is contained inside a control's children // return the child return getFocused(c.Controls); }

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; } }

How can I make the SplitContainer continuously update its contents while the splitter is moving?
Note: Continuously updating a SplitContainers contents can lead to poor performance, and
should be used sparingly.

By default, when moving a SplitContainers splitter a preview is shown of the splitters future location. Then when the splitter is released, the SplitContainer resizes to that position. If you want the SplitContainer to be constantly resizing as the splitter is moving, you can do one of two things: 1. Use the custom control defined in the ContinuousUpdate sample 2. Insert the following code in your project, and attach these events to all of the SplitContainers that you want to continuously update.
private void splitContainer_MouseDown(object sender, MouseEventArgs e) { // This disables the normal move behavior ((SplitContainer)sender).IsSplitterFixed = true; }

private void splitContainer_MouseUp(object sender, MouseEventArgs e) { // This allows the splitter to be moved normally again ((SplitContainer)sender).IsSplitterFixed = false; } private void splitContainer_MouseMove(object sender, MouseEventArgs e) { // Check to make sure the splitter won't be updated by the // normal move behavior also if (((SplitContainer)sender).IsSplitterFixed) { // Make sure that the button used to move the splitter // is the left mouse button if (e.Button.Equals(MouseButtons.Left)) { // Checks to see if the splitter is aligned Vertically if (((SplitContainer)sender).Orientation.Equals(Orientation.Vertical)) { // Only move the splitter if the mouse is within // the appropriate bounds if (e.X > 0 && e.X < ((SplitContainer)sender).Width) { // Move the splitter ((SplitContainer)sender).SplitterDistance = e.X; } } // If it isn't aligned vertically then it must be // horizontal else { // Only move the splitter if the mouse is within // the appropriate bounds if (e.Y > 0 && e.Y < ((SplitContainer)sender).Height) { // Move the splitter ((SplitContainer)sender).SplitterDistance = e.Y; } } } // If a button other than left is pressed or no button // at all else { // This allows the splitter to be moved normally again ((SplitContainer)sender).IsSplitterFixed = false; } } }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy