コンテナのレイヤーを実行する必要があるプロジェクトがあります。
コンテナーには次のようなものが必要です。
Form.Opacity = 0;
ユーザーは最上位レイヤーの下の要素を見ることができますが、それらを使用することはできません。
透明な背景を持つ多くの例を見てきましたが、私のやり方では、このコンテナ上の要素を移動する必要があります. 私が見つけたより良いもの:
class xPanel : Panel
{
public xPanel()
{
SetStyle(ControlStyles.Opaque, true);
}
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT
return createParams;
}
}
protected override void OnPaint(PaintEventArgs e)
{
//PaintParentBackground(e);
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0, Color.White)),
0, 0, Width, Height);
}
public void InvalidateEx()
{
if (Parent == null)
return;
Rectangle rc = new Rectangle(this.Location, this.Size);
Parent.Invalidate(rc, true);
}
}
ただし、要素をドラッグしている間、または再描画時に点滅している間は軌跡があります。
この問題を解決する方法がわかりません。アイデアはありますか?
私は InvalidateEx() を使用します:
protected override void OnLocationChanged(EventArgs e)
{
if (Parent != null)
((xPanel)Parent).InvalidateEx();
}