当含有prevent自动滚屏控制获得焦点 [英] Prevent AutoScroll when contained Control gets focus
问题描述
我有一个面板
有两个按钮
S上的,其中之一是部分隐藏。当部分隐藏的按钮获得焦点 - 另一种是点击时,例如,然后它(-The原件)点击 - 面板获取滚动。
我需要垂直滚动条,但不是的汽车的滚动,而且似乎没有办法得到一个有效的滚动条没有自动滚动。
在code:
使用System.Drawing中;
使用System.Windows.Forms的;
命名空间测试
{
公共部分类Form1中:形态
{
面板面板=新面板
{
自动滚屏= TRUE,
大小=新的大小(200,200),
位置=新的点(0,30),
};
按钮B1 =新按钮
{
位置=新的点(100,100),
大小=新的大小(50,150),
背景色= Color.Black
};
按钮B2 =新按钮();
公共Form1中()
{
的InitializeComponent();
panel.Controls.Add(B1);
Controls.Add被(板);
Controls.Add被(B2);
}
}
}
使用它可以访问VSCROLL财产派生类。
但更简单,效果更好:
覆盖 ScrollToControl
。请参阅<一href="http://stackoverflow.com/questions/419774/how-can-you-stop-a-winforms-panel-from-scrolling/912610#912610">How你可以从滚动停止的WinForms面板?。
I have a Panel
with two Button
s on it, one of which is partially hidden. When the partially-hidden button gets focus - such as when the other is clicked and then it (-the original) is clicked - the panel gets scrolled.
I need the vertical scrollbar but not the auto scrolling, and there seems to be no way of getting a functioning scrollbar without the auto scrolling.
The code:
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);
}
}
}
Use a derived class which can access the VScroll property.
But more simply and works better:
Override ScrollToControl
. See How can you stop a Winforms Panel from scrolling? .
这篇关于当含有prevent自动滚屏控制获得焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!