MSDN example代码

http://msdn.microsoft.com/en-us/library/system.windows.forms.splitcontainer(VS.85).aspx
  1     public partial class Form1 : Form
  2     {
  3         private System.Windows.Forms.SplitContainer splitContainer2;
  4         private System.Windows.Forms.ListView listView2;
  5         private Label nlab1;
  6 
  7         public Form1()
  8         {
  9             {
 10                 splitContainer1 = new System.Windows.Forms.SplitContainer();
 11                 treeView1 = new System.Windows.Forms.TreeView();
 12                 splitContainer2 = new System.Windows.Forms.SplitContainer();
 13                 listView1 = new System.Windows.Forms.ListView();
 14                 listView2 = new System.Windows.Forms.ListView();
 15                 splitContainer1.SuspendLayout();
 16                 splitContainer2.SuspendLayout();
 17                 SuspendLayout();
 18 
 19                 // Basic SplitContainer properties.
 20                 // This is a vertical splitter that moves in 10-pixel increments.
 21                 // This splitter needs no explicit Orientation property because Vertical is the default.
 22                 splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
 23                 splitContainer1.ForeColor = System.Drawing.SystemColors.Control;
 24                 splitContainer1.Location = new System.Drawing.Point(0, 0);
 25                 splitContainer1.Name = "splitContainer1";
 26                 // You can drag the splitter no nearer than 30 pixels from the left edge of the container.
 27                 splitContainer1.Panel1MinSize = 30;
 28                 // You can drag the splitter no nearer than 20 pixels from the right edge of the container.
 29                 splitContainer1.Panel2MinSize = 20;
 30                 splitContainer1.Size = new System.Drawing.Size(292, 273);
 31                 splitContainer1.SplitterDistance = 79;
 32                 // This splitter moves in 10-pixel increments.
 33                 splitContainer1.SplitterIncrement = 10;
 34                 splitContainer1.SplitterWidth = 6;
 35                 // splitContainer1 is the first control in the tab order.
 36                 splitContainer1.TabIndex = 0;
 37                 splitContainer1.Text = "splitContainer1";
 38                 // When the splitter moves, the cursor changes shape.
 39                 splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(splitContainer1_SplitterMoved);
 40                 splitContainer1.SplitterMoving += new System.Windows.Forms.SplitterCancelEventHandler(splitContainer1_SplitterMoving);
 41 
 42 //                 // Add a TreeView control to the left panel.
 43                 splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.Control;
 44                 // Add a TreeView control to Panel1.
 45                 splitContainer1.Panel1.Controls.Add(treeView1);
 46                 splitContainer1.Panel1.Name = "splitterPanel1";
 47                 // Controls placed on Panel1 support right-to-left fonts.
 48                 splitContainer1.Panel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
 49  
 50 
 51                 // Add a SplitContainer to the right panel.
 52                 splitContainer1.Panel2.Controls.Add(splitContainer2);
 53                 splitContainer1.Panel2.Name = "splitterPanel2";
 54 
 55                 // This TreeView control is in Panel1 of splitContainer1.
 56                 treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
 57                 treeView1.ForeColor = System.Drawing.SystemColors.InfoText;
 58                 treeView1.ImageIndex = -1;
 59                 treeView1.Location = new System.Drawing.Point(0, 0);
 60                 treeView1.Name = "treeView1";
 61                 treeView1.SelectedImageIndex = -1;
 62                 treeView1.Size = new System.Drawing.Size(79, 273);
 63                 // treeView1 is the second control in the tab order.
 64                 treeView1.TabIndex = 1;
 65 
 66                 // Basic SplitContainer properties.
 67                 // This is a horizontal splitter whose top and bottom panels are ListView controls. The top panel is fixed.
 68                 splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
 69                 // The top panel remains the same size when the form is resized.
 70                 splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
 71                 splitContainer2.Location = new System.Drawing.Point(0, 0);
 72                 splitContainer2.Name = "splitContainer2";
 73                 // Create the horizontal splitter.
 74                 splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
 75                 splitContainer2.Size = new System.Drawing.Size(207, 273);
 76                 splitContainer2.SplitterDistance = 125;
 77                 splitContainer2.SplitterWidth = 6;
 78                 // splitContainer2 is the third control in the tab order.
 79                 splitContainer2.TabIndex = 2;
 80                 splitContainer2.Text = "splitContainer2";
 81 
 82                 // This splitter panel contains the top ListView control.
 83                // splitContainer2.Panel1.Controls.Add(listView1);
 84                 splitContainer2.Panel1.Name = "splitterPanel3";
 85 
 86                 // This splitter panel contains the bottom ListView control.
 87                 splitContainer2.Panel2.Controls.Add(listView2);
 88                 splitContainer2.Panel2.Name = "splitterPanel4";
 89 
 90                 // This ListView control is in the top panel of splitContainer2.
 91                 listView1.Dock = System.Windows.Forms.DockStyle.Fill;
 92                 listView1.Location = new System.Drawing.Point(0, 0);
 93                 listView1.Name = "listView1";
 94                 listView1.Size = new System.Drawing.Size(207, 125);
 95                 // listView1 is the fourth control in the tab order.
 96                 listView1.TabIndex = 3;
 97 
 98                 // This ListView control is in the bottom panel of splitContainer2.
 99                 listView2.Dock = System.Windows.Forms.DockStyle.Fill;
100                 listView2.Location = new System.Drawing.Point(0, 0);
101                 listView2.Name = "listView2";
102                 listView2.Size = new System.Drawing.Size(207, 142);
103                 // listView2 is the fifth control in the tab order.
104                 listView2.TabIndex = 4;
105 
106                 // These are basic properties of the form.
107                 ClientSize = new System.Drawing.Size(292, 273);
108                 Controls.Add(splitContainer1);
109                 Name = "Form1";
110                 Text = "Form1";
111                 splitContainer1.ResumeLayout(false);
112                 splitContainer2.ResumeLayout(false);
113                 ResumeLayout(false);
114 
115 
116                 TreeNode rootnode = new TreeNode("root");
117                 TreeNode chil1 = new TreeNode("chil1");
118                 TreeNode chil2 = new TreeNode("chil2");
119                 rootnode.Nodes.AddRange(new TreeNode[]{chil1,chil2});
120                 treeView1.Nodes.Add(rootnode);
121 
122              
123                 
124                 //splitContainer2.Panel2.Controls.Add(treeView1);
125             }
126 
127 
128 
129 
130             InitializeComponent();
131             int atm=Properties.Settings.Default.mylocal;
132           //  MessageBox.Show("val is :" + atm);
133             Properties.Settings.Default.mylocal = ++atm;
134             Properties.Settings.Default.Save();
135 
136 
137             nlab1 = new Label();
138             nlab1.Text = "test1";
139             nlab1.Dock = DockStyle.Bottom;
140 
141             nlab1.Size = new System.Drawing.Size(41, 12);
142             nlab1.AutoSize = true;
143             nlab1.TabIndex = 0;
144             nlab1.Text = "label1";
145             nlab1.Dock = DockStyle.Left;
146             nlab1.ForeColor = Color.Black;
147             //splitContainer2.Panel1.Controls.Clear();            
148             splitContainer2.Panel1.Controls.Add(nlab1);
149             //this.BackColor = Color.Cyan;
150         
151             
152             //nlab1.Location = new System.Drawing.Point(52, 43);
153             //nlab1.Name = "label1";
154 
155 
156         }
157         private void splitContainer1_SplitterMoving(System.Object sender, System.Windows.Forms.SplitterCancelEventArgs e)
158         {
159             // As the splitter moves, change the cursor type.
160             Cursor.Current = System.Windows.Forms.Cursors.NoMoveVert;
161         }
162         private void splitContainer1_SplitterMoved(System.Object sender, System.Windows.Forms.SplitterEventArgs e)
163         {
164             // When the splitter stops moving, change the cursor back to the default.
165             Cursor.Current = System.Windows.Forms.Cursors.Default;
166         }
SplitContainer用法http://msdn.microsoft.com/en-us/library/system.windows.forms.splitcontainer(VS.85).aspx

 

posted on 2013-09-10 16:40  zhiying678  阅读(156)  评论(0编辑  收藏  举报

导航