アプリケーションで完全に透明なモーダルフォームを使用したいと思います。部分的に透過的なイメージで塗りつぶすことができます。このために、フォームからすべての表示要素を削除して、以下のコードを取得しました。C# - ウィンドウ上の透明なモーダルフォーム
class WinScreenshotWindow : Form
{
public WinScreenshotWindow()
{
// Create from without erasing background with a color
// Going not to use transparent form instead, it will produce context menu bugs in textboxes for child form
this.SuspendLayout();
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.Manual;
this.ControlBox = false;
this.Visible = false;
this.Size = new Size(100, 100);
this.Location = new Point(200, 200);
this.ResumeLayout();
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// Erase Background Windows message:
}
protected override void OnPaint(PaintEventArgs e)
{
Rectangle clientRect = e.ClipRectangle;
e.Graphics.FillRectangle(Brushes.Transparent, clientRect);
}
}
static void Main()
{
Form form = new Form();
form.Size = new Size(400, 400);
form.Show();
var ww = new WinScreenshotWindow();
ww.ShowDialog(form);
}
しかし、結果は奇妙なものです:私はのOnPaint()に記入削除すると、それがすべて表示されていない
。 質問は - なぜこれが起こるのですか?背景が透明であれば、なぜこのようにフォームが表示されますか?そして、このような状況で何ができるでしょうか?
助けてください。
背景を塗っていないと、ランダムなピクセルが得られます。 TransparencyKeyを使用します。 –