【发布时间】:2017-04-05 11:42:56
【问题描述】:
我正在通过扩展 ScrollableControl 来构建自定义控件。
问题是我的自定义控件充当容器 - 我可以将控件拖入其中:
我的问题是如何在扩展 ScrollableControl 的类中禁用容器功能
下面是两个测试控件,一个扩展Control,第二个ScrollableControl
public class ControlBasedControl : Control
{
protected override Size DefaultSize
{
get { return new Size(100, 100); }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.LightCoral, ClientRectangle);
}
}
public class ScrollableControlBasedControl : ScrollableControl
{
public ScrollableControlBasedControl()
{
AutoScrollMinSize = new Size(200, 200);
}
protected override Size DefaultSize
{
get { return new Size(100, 100); }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.LawnGreen, ClientRectangle);
}
}
【问题讨论】:
-
也许,您可以尝试将Drop Event处理为空Container属性或清除目标控件中的子项。
-
@BaranovskiyDmitry 我想在设计时禁用它。 Drop Event 将在运行时起作用。
标签: c# .net winforms user-controls