C#で透明・半透明フォームを作る
2018/10/07
C#でフォームを透明(または半透明)にする方法です。
フォームの透明度はFormの Opacityプロパティで簡単に設定できます。
[ad#top-1]
Opacityプロパティに指定できる値は、0.0(完全に透明)~1.0(完全に不透明)の間です。0.5にすると以下のようになります。
Fromクラスを拡張したクラスで以下のように記述すると透明/半透明フォームができます。値が0.5なので透明度50%の半透明のフォームが作れます。
this.Opacity = 0.5;
こちらがソースコード全文です。
using System; using System.Drawing; using System.Windows.Forms; class Messenger{ static void Main(){ Application.Run(new MainWindow()); } } class MainWindow : Form{ public MainWindow(){ this.StartPosition = FormStartPosition.CenterScreen; this.Width = 300; this.Height = 200; this.Text = "透明ウィンドウ"; this.Opacity = 0.5; new Label(){ Font = new Font("Meiryo UI", 18), Dock = DockStyle.Fill, Location = new Point(5, 5), Text = "Hello World", Parent = this, }; } }
[ad#ad-1]
スポンサーリンク