C # win forms make controls mutable

I have a panel with two controls inside. I would like them to be attached to the border of the panel (the panel has some width and height that cannot be changed), but have the ability to change the size of the space that they (controls) receive from the panel in the vertical direction.

panel.Controls.Add(listview1);
panel.Controls.Add(listview2);

Two lists are displayed one after the other (vertically). I want to be able to "change the height" of them (by choosing the border between them to resize).

I hope you understand what I mean. Thanks for your help in advance.

+5
source share
5 answers
+2

doc . (). Dock . .

+2

, SplitContainer - , . , Dock Anchor , split. Dock Fill, , , . Anchor , . Anchor, , "" . . .

In addition, you will want to set the properties Dockeither Anchorin the element itself SplitContainer. This will resize when the size of the form changes. Then setting the Anchor/ properties Dockon the child controls inside SplitContainerwill cause the children to resize when the container is resized.

+2
source

Have you considered using Anchor in ListViews?

        this.panel1 = new System.Windows.Forms.Panel();
        this.listView1 = new System.Windows.Forms.ListView();
        this.listView2 = new System.Windows.Forms.ListView();
        this.panel1.SuspendLayout();
        this.SuspendLayout();
        // 
        // panel1
        // 
        this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
        | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this.panel1.Controls.Add(this.listView2);
        this.panel1.Controls.Add(this.listView1);
        this.panel1.Location = new System.Drawing.Point(12, 12);
        this.panel1.Name = "panel1";
        this.panel1.Size = new System.Drawing.Size(413, 280);
        this.panel1.TabIndex = 0;
        // 
        // listView1
        // 
        this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this.listView1.Location = new System.Drawing.Point(3, 0);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(410, 97);
        this.listView1.TabIndex = 0;
        this.listView1.UseCompatibleStateImageBehavior = false;
        // 
        // listView2
        // 
        this.listView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this.listView2.Location = new System.Drawing.Point(0, 183);
        this.listView2.Name = "listView2";
        this.listView2.Size = new System.Drawing.Size(410, 97);
        this.listView2.TabIndex = 1;
        this.listView2.UseCompatibleStateImageBehavior = false;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(437, 304);
        this.Controls.Add(this.panel1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.panel1.ResumeLayout(false);
        this.ResumeLayout(false);
+1
source

All Articles