There is a User Control of type Panel with property "BindingContainer", which places the UC in the desired container.
When trying to remove ONLY UC - no problem. But if you set the "BindingContainer" property using the "Properties window" and try to delete (a container with an element inside it), a "denenv.exe - System error" - Failed to create a new protection page for the stack. Visual Studio closes.
-- UC TransparentPanel --
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;
}
}