Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Created September 6, 2021 05:21
Show Gist options
  • Save daichan4649/5141a60d69c063b024bdcccb2641e254 to your computer and use it in GitHub Desktop.
Save daichan4649/5141a60d69c063b024bdcccb2641e254 to your computer and use it in GitHub Desktop.
[Windows Form] show overlay crosshair
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