有一个属性为“BindingContainer”的Panel类型用户控件,它将UC放置在所需的容器中。
当尝试仅移除UC时-没有问题。但是,如果使用“属性”窗口设置“BindingContainer”属性并尝试删除(其中包含元素的容器),则会出现“denenv.exe -系统错误”-无法为堆栈创建新的保护页。Visual Studio将关闭。
-- UC透明面板--
public class TransparentPanel : Panel {
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e) {
//base.OnPaintBackground(e);
}
protected override void OnCreateControl() {
base.OnCreateControl();
if (!DesignMode && BindingContainer != null) {
this.Size = new Size(BindingContainer.Width - 20, BindingContainer.Height);
this.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
this.BringToFront();
}
}
public new bool DesignMode { get; } =
(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv");
private Control bindingContainer;
public Control BindingContainer {
get { return bindingContainer; }
set {
bindingContainer = value;
BindingContainerChanged();
}
}
private void BindingContainerChanged() {
if (BindingContainer == null) return;
BindingContainer.Controls.Add(this);
this.Location = new Point(0, 0);
this.Size = new Size(15, BindingContainer.Height);
this.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
}
}
1条答案
按热度按时间gorkyyrv1#
正常工作的代码。