Splitcontainer control (Windows form)

Source: Internet
Author: User
Tags microsoft outlook

1. The windows form splitcontainer control can be considered as a complex, which is a two-Panel separated by a removable split bar. When the mouse pointer is hovering over the shard, the pointer changes the shape accordingly to show that the Shard is movable.

UseSplitcontainerControl, you can create a composite User Interface (usually, the selection in one panel determines which objects are displayed in another panel ). This sort is useful for displaying and browsing information. Two panels enable you to aggregate information in different regions, and you can easily adjust the Panel size by using a split bar (also known as a "splitter.

You can also nest multipleSplitcontainerControl, and the secondSplitcontainerControls can be placed horizontally to generate the upper and lower panels.

Please note that,SplitcontainerControls can be accessed by keyboard by default. If the issplitterfixed attribute is setFalseYou can press the arrow keys to move the splitter.

SplitcontainerThe orientation attribute of the control determines the direction of the splitter, rather than the control's own direction. Therefore, when this attribute is set to vertical, the splitter is placed vertically to generate the Left and Right panels.

In addition, note that the value of the splitterrectangle attribute isOrientationAttribute Value. For more information, seeSplitterrectangleAttribute.

You can also limitSplitcontainerWidget size and movement. Fixedpanel attribute adjustmentSplitcontainerWhich panel will keep the original size after the control size,IssplitterfixedProperty determines whether the splitter can be moved by keyboard or mouse.

 

Common attributes, methods, and events

Name Description

FixedpanelAttribute

Confirm AdjustmentSplitcontainerControl size, which panel will keep the original size.

IssplitterfixedAttribute

Determine whether the splitter can be moved with the keyboard or mouse.

OrientationAttribute

Determine whether the splitter is placed vertically or horizontally.

SplitterdistanceAttribute

Determine the distance (in pixels) from the left or top edge to the removable split bar ).

Splitterincrement attributes

Determines the shortest distance (in pixels) that the user can move the splitter ).

Splitterwidth attribute

Determine the splitter thickness (in pixels ).

Splittermoving event

The splitter is moved.

Splittermoved event

The splitter is moved.

2. How to: Define the size adjustment and positioning behavior in the split window

You can easily resize the splitcontainer control panel and perform various operations on it. However, sometimes you may want to programmatically control the position of the splitter and the degree to which it can be moved.

ExploitationSplitcontainerThe splitterincrement attribute and other attributes on the control allow you to precisely control user interface behavior based on your needs. The following table lists these attributes.

Name Description

Issplitterfixed attributes

Determine whether the splitter can be moved by keyboard or mouse.

Splitterdistance attributes

Determine the distance (in pixels) from the left or top edge to the removable split bar ).

SplitterincrementAttribute

Determines the shortest distance (in pixels) that the user can move the splitter ).

The following example modifiesSplitterincrementAttribute to create an alignment splitter. When you drag the splitter, it increments by 10 pixels instead of the default one pixel.

Define splitcontainer size adjustment behavior
    • In the processSplitterincrementAttribute is set to the desired size to achieve the "alignment" behavior of the splitter.

      In the followingCodeIn the load event of the formSplitcontainerThe splitter in the control is set to skip 10 pixels when dragging.

    • C # copy code
      Private VoidFormateload (system. Object sender, system. eventargs e) {splitcontainer splitsnapper =NewSplitcontainer (); splitsnapper. splitterincrement = 10; splitsnapper. Dock = dockstyle. Fill; splitsnapper. Parent =This;}

      (Visual C #) place the following code in the form constructor to register for event processingProgram.

      C # copy code
      This. Load + =NewSystem. eventhandler (This. Form1_load); 3. How to split the window horizontally
    •     
Horizontal Split Window
  • In the programSplitcontainerControlOrientationSet the attribute to horizontal.

  • C # copy code
    Public VoidShowsplitcontainer () {splitcontainer splitcontainer1 =NewSplitcontainer (); splitcontainer1.borderstyle = borderstyle. fixed3d; splitcontainer1.location =NewSystem. Drawing. Point (74, 20); splitcontainer1.name ="Demosplitcontainer"; Splitcontainer1.size =NewSystem. Drawing. Size (212,435); splitcontainer1.tabindex = 0; splitcontainer1.orientation = orientation. horizontal;This. Controls. Add (splitcontainer1 );}
  • 4. How to: use Windows Forms to create a multi-pane user interface
  • In the following process, you will create a multi-pane User Interface similar to that used in Microsoft Outlook, which contains the folder list, mail pane, and Preview pane. This arrangement is mainly implemented by dock controls on the form.

    When you dock the control, you can determine which edge of the control is close to the parent container. In this way, if the dock property is set to right, the right edge of the control is docked to the right edge of its parent control. In addition, the size of the dock edge of the control is adjusted to match the size of its container control. RelatedDockFor more information about how the properties work, see How to: dock controls on Windows Forms.

    The focus of this process is to arrange the splitcontainer and other controls on the form, rather than adding features so that the application is similar to Microsoft Outlook.

    To create this user interface, place all the controls inSplitcontainerControls (the left-side panel contains the Treeview control.SplitcontainerThe right panel of the control contains anotherSplitcontainerControl, where the listview control is above the RichTextBox Control. TheseSplitcontainerControls Support adjusting the sizes of other controls on the form. You can adapt the methods in this process to create your own Custom User Interface.

    Create an outlook User Interface programmatically
    1. In the form, declare each control that forms the user interface. This example usesTreeview,Listview,SplitcontainerAndRichTextBoxControl to create a user interface similar to Microsoft Outlook.

C # copy code
Private System. Windows. Forms. Treeview treeview1; Private System. Windows. Forms. listview listview1; Private System. Windows. Forms. RichTextBox richtextbox1; Private System. Windows. Forms. splitcontainer splitcontainer2; Private System. Windows. Forms. splitcontainer splitcontainer1;

Create a user interface. The following code sets properties so that the form is similar to the Microsoft Outlook user interface. However, by using other controls or stopping them at different locations, you can easily create other user interfaces with the same flexibility.

C # copy code
 Public   Void Createoutlookui (){ // Create an instance of each control being used. Treeview1 =New System. Windows. Forms. Treeview (); listview1 = New System. Windows. Forms. listview (); richtextbox1 = New System. Windows. Forms. RichTextBox (); splitcontainer2 = New System. Windows. Forms. splitcontainer (); splitcontainer1 = New System. Windows. Forms. splitcontainer (); // Insert code here to hook up event methods.  // Set Properties of Treeview control. Treeview1.dock = system. Windows. Forms. dockstyle. Fill; treeview1.tabindex = 0; treeview1.nodes. Add ( "Treeview" );// Set Properties of listview control. Listview1.dock = system. Windows. Forms. dockstyle. Top; listview1.tabindex = 2; listview1.items. Add ( "Listview" ); // Set Properties of RichTextBox Control. Richtextbox1.dock = system. Windows. Forms. dockstyle. Fill; richtextbox1.tabindex = 3; richtextbox1.text = "Richtextbox1" ; // Set Properties of first splitcontainer control. Splitcontainer1.dock = system. Windows. Forms. dockstyle. fil1; splitcontainer2.tabindex = 1; Metrics = 4; Metrics = 150; splitcontainer2.orientation = orientation. Horizontal; controls. Controls. Add ( This . Listview1); splitcontainer2.panel1. Controls. Add ( This . Richtextbox1 ); // Set Properties of second splitcontainer control. Splitcontainer2.dock = system. Windows. Forms. dockstyle. fil1; splitcontainer2.tabindex = 4; splitcontainer2.splitterwidth = 4; controls = 100; splitcontainer2.panel1. Controls. Add ( This . Treeview1); splitcontainer2.panel1. Controls. Add ( This . Splitcontainer1 ); // Add the main splitcontainer control to the form.  This . Controls. Add ( This . Splitcontainer2 ); This . Text ="Intricate UI example" ;} In Visual Basic, add New () The call of the newly created process. In Visual C #, add this line of code to the constructor of the Form class.

Address: http://blog.163.com/lina_qiu/blog/static/228156020077275124411/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.