在问了这个问题后:当包含控件获得焦点时防止 AutoScroll我找到了一种没有 AutoScroll 的滚动条的方法(使用可以访问该VScroll
属性的派生类)。但是 - 它不是实时的。即只有当用户完成滚动时,控件才会真正滚动。(与带有 . 的面板相反AutoScroll = true
。)那么我如何让它实时滚动呢?
我的代码:
using System.Drawing;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
MyPanel panel = new MyPanel
{
//AutoScroll = true,
Size = new Size(200, 200),
Location = new Point(0, 30),
BackColor = Color.Green
};
Button b1 = new Button
{
Location = new Point(100, 100),
Size = new Size(50, 150),
BackColor = Color.Black
};
Button b2 = new Button();
public Form1()
{
InitializeComponent();
panel.Controls.Add(b1);
Controls.Add(panel);
Controls.Add(b2);
Shown += new System.EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, System.EventArgs e)
{
panel.VerticalScroll.Visible = true;
panel.SetV();
}
}
class MyPanel : Panel
{
public void SetV() { VScroll = true; }
}
}