使用 C#.NET 4.5
我试图在进入时打开用户控件
change
的vScrollbar 属性,在离开控件 时关闭。我使用
Mouse_Enter
andMouse_Leave
,但是当离开另一个(确实显示)时,滚动条消失了。control or the scroll bar
问题: 如何检查鼠标是否在用户控制区域内?
问题2:如何禁用用户控件底部的滚动条?(水平滚动条)
如果您需要更多信息或者我不清楚某处,请告诉我。任何帮助将不胜感激,在此先感谢!
编辑:这是用户控件的代码:
public partial class EnemyStats : UserControl
{
public EnemyStats()
{
InitializeComponent();
label1.Left = (this.Width / 2) - (label1.Width / 2);
hpBar1.Width = this.Width - 8;
// Here i add the event that shows the scrollbar to all controls;
foreach (Control con in this.Controls)
{
con.MouseEnter += new EventHandler(EnemyStats_MouseEnter);
}
}
public double enemyMaxHP
{
get
{
return hpBar1.maxValue;
}
set
{
hpBar1.maxValue = value;
}
}
public double enemyHP
{
get
{
return hpBar1.Value;
}
set
{
hpBar1.Value = value;
}
}
private void EnemyStats_SizeChanged(object sender, EventArgs e)
{
if (this.Width < label1.Width) this.Width = label1.Width;
label1.Left = (this.Width / 2) - (label1.Width / 2);
hpBar1.Width = this.Width - 8;
}
private void EnemyStats_MouseEnter(object sender, EventArgs e)
{
// This scrollbar was added by dragging it from the toolbox onto the user control in the designer
vScrollbar1.Visible = true;
}
private void EnemyStats_MouseLeave(object sender, EventArgs e)
{
// This scrollbar was added by dragging it from the toolbox onto the user control in the designer
vScrollbar1.Visible = false;
}
}
但是滚动条不起作用:
public void randomMethodInUserControl()
{
this.ScrollBars = ScrollBars.Vertical;
}