Skip to content

Instantly share code, notes, and snippets.

@KOZ60
Last active May 20, 2024 02:26
Show Gist options
  • Save KOZ60/24e239463adcfc62734a1f58ceed023d to your computer and use it in GitHub Desktop.
Save KOZ60/24e239463adcfc62734a1f58ceed023d to your computer and use it in GitHub Desktop.
メインフォームを非表示でアプリケーションを立ち上げるには

メインフォームを非表示でアプリケーションを立ち上げるには、SetVisibleCore を オーバーライドして、初回の引数を false にします。 Load イベントが起きなくなるので、HandleCreated イベントなどで代用するといいでしょう。

public partial class MainForm : Form
{
    private bool firstTimeVisible = true;

    public MainForm() {
        InitializeComponent();
    }

    protected override void SetVisibleCore(bool value) {
        if (firstTimeVisible) {
            firstTimeVisible = false;
            value = false;
            CreateHandle();
        }
        base.SetVisibleCore(value);
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment