2012-12-18 99 views
4

我有一个winform应用程序,我有一个面板控件。面板垂直滚动

enter image description here

我希望能够到面板和地方控制垂直更多的内部滚动,则控制的当前高度,然后有一个滚动,这将有助于我看到所有的控制,我如何能实现那?

这是设计师的代码为好,万一有人想看看代码:

private void InitializeComponent() 
{ 
    this.panel1 = new System.Windows.Forms.Panel(); 
    this.SuspendLayout(); 
    // 
    // panel1 
    // 
    this.panel1.AutoScroll = true;   
    this.panel1.BackColor = System.Drawing.SystemColors.ControlLightLight; 
    this.panel1.Location = new System.Drawing.Point(12, 12);  
    this.panel1.Name = "panel1"; 
    this.panel1.Size = new System.Drawing.Size(267, 365); 
    this.panel1.TabIndex = 0; 
    // 
    // Form2 
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
    this.ClientSize = new System.Drawing.Size(456, 410); 
    this.Controls.Add(this.panel1); 
    this.Name = "Form2"; 
    this.Text = "Form2"; 
    this.ResumeLayout(false); 
} 

回答

4

既然你有自动滚屏= true时,你不应该做任何事情。您在面板下方放置的任何控件都将自动在面板中创建适当的滚动距离。

如果你想手动重写,设定自动卷动= false,并使用AutoScrollMinSize属性还设置画布的大小自己,例如:

panel1.AutoScrollMinSize = new Size(0, 1200); 

你可能要考虑的面板锚定到四边的形式,或码头填充,因为它看起来像一个可调整大小的形式。同样,面板将为您处理滚动条的大小。

0

试试在MDIForm面板中加载其他表单。它完美的作品。

myForm.TopLevel = false; 
myForm.AutoScroll = true; 
main_panel.Controls.Clear(); 
main_panel.Controls.Add(myForm); 
main_panel.AutoScrollMinSize = new Size(0, myForm.Height); 
myForm.Show();