Created
September 6, 2021 05:21
-
-
Save daichan4649/5141a60d69c063b024bdcccb2641e254 to your computer and use it in GitHub Desktop.
[Windows Form] show overlay crosshair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Drawing; | |
using System.Windows.Forms; | |
namespace crosshair | |
{ | |
class CrosshairForm : Form | |
{ | |
public CrosshairForm() | |
{ | |
// Form 設定 | |
string iconPath = @"./xxx.ico"; //iconファイルパス | |
Icon icon = new Icon(iconPath, 128, 128); | |
this.Icon = icon; | |
StartPosition = FormStartPosition.CenterScreen; | |
TopMost = true; | |
FormBorderStyle = FormBorderStyle.None; | |
TransparencyKey = BackColor; | |
Opacity = 0.2; | |
// クロスヘア | |
Label lbl = new Label | |
{ | |
AutoSize = false, | |
TextAlign = ContentAlignment.MiddleCenter, | |
Dock = DockStyle.Fill, | |
}; | |
lbl.Font = new Font(lbl.Name, 30f, lbl.Font.Style); | |
lbl.ForeColor = Color.White; | |
lbl.Text = "◯"; | |
Controls.Add(lbl); | |
} | |
/// <summary> | |
/// クリックイベントの透過 | |
/// </summary> | |
protected override CreateParams CreateParams | |
{ | |
get | |
{ | |
CreateParams cp = base.CreateParams; | |
cp.ExStyle |= 0x00000020; | |
return cp; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment