![](/img/trans.png)
[英]How to make System.Windows.Forms.Panel fill the container in WPF when created in C#?
[英]How to disable a Horizontal Scrollbar in C# System.Windows.Forms.Panel
除非通过Panel.AutoScroll = false
和panel1.HorizontalScroll.Visible = true
进行静态设置,否则面板不会显示条形图。 我建议您确认没有控件超出面板范围,而不是强制执行状态。
将以下内容插入表单的某些部分。 这将验证您没有控件超出面板的侧面。 将panel1更改为有问题的面板的名称。
foreach (Control comp in panel1.Controls)
{
if (comp.Right >= panel1.Width || comp.Bottom >= panel1.Height)
{
System.Diagnostics.Debugger.Break();
}
}
如果仍然找不到问题, Panel.AutoScroll = false
应该执行Panel.AutoScroll = false
和panel1.HorizontalScroll.Visible = false
。
我发现此解决方案是首选。
public class MongoDataPanel : Panel
{
[DllImport("user32.dll")]
static public extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
protected override void OnResize(EventArgs eventargs)
{
base.OnResize(eventargs);
if (this.Parent != null)
{
if (this.Parent.Width > this.PreferredSize.Width - 10)
{
try
{
ShowScrollBar(this.Handle, SB_HORZ, false);
}
catch (Exception e) { }
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.