c# Windows_Forms 背景が透明なウィンドウ
方法①
Form1.cs
using System.Drawing; using System.Windows.Forms; namespace TransparentWindowSample { public partial class Form1 : Form { public Form1() { InitializeComponent(); //ウィンドウを透明に Start //ここの色は何でもよい BackColor = Color.Red; TransparencyKey = BackColor; //ウィンドウを透明に End } } }
方法②
Formクラスの継承した実装にOnPaint(PaintEventArgs e)メソッドを用意
Form1.cs
using System.Drawing; using System.Windows.Forms; namespace TransparentWindowSample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //ウィンドウを透明に Start protected override void OnPaint(PaintEventArgs e) { //ここの色は何でもよい TransparencyKey = Color.Red; e.Graphics.FillRectangle(new SolidBrush(TransparencyKey), ClientRectangle); base.OnPaint(e); } //ウィンドウを透明に End } }