【问题标题】:Prevent AutoScroll when contained Control gets focus当包含的控件获得焦点时防止自动滚动
【发布时间】:2013-10-16 01:17:44
【问题描述】:

我有一个Panel,上面有两个Button,其中一个是部分隐藏的。当部分隐藏的按钮获得焦点时 - 例如单击另一个按钮然后单击它(原始)时 - 面板会滚动。 我需要垂直滚动条,但不需要 auto 滚动,如果没有自动滚动,似乎无法获得正常工作的滚动条。

代码:

using System.Drawing;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        Panel panel = new Panel
        {
            AutoScroll = true,
            Size = new Size(200, 200),
            Location = new Point(0, 30),
        };
        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);
        }
    }
}

【问题讨论】:

    标签: c# .net winforms


    【解决方案1】:

    使用可以访问 VScroll 属性的派生类。

    但更简单,效果更好:

    覆盖ScrollToControl。见How can you stop a Winforms Panel from scrolling?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 2013-11-26
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      相关资源
      最近更新 更多