Advertisement
areyesram

C# Windows Forms Singleton

May 18th, 2022
480
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Windows.Forms;
  2.  
  3. namespace Ventus
  4. {
  5.     public partial class SingletonForm : Form
  6.     {
  7.         private SingletonForm()
  8.         {
  9.             InitializeComponent();
  10.         }
  11.  
  12.         private static SingletonForm _instance;
  13.  
  14.         public static SingletonForm Instance
  15.         {
  16.             get
  17.             {
  18.                 if (_instance == null)
  19.                     _instance = new SingletonForm();
  20.                 return _instance;
  21.             }
  22.         }
  23.  
  24.         private void SingletonForm_FormClosed(object sender, FormClosedEventArgs e)
  25.         {
  26.             _instance = null;
  27.         }
  28.     }
  29. }
Advertisement
RAW Paste Data Copied
Advertisement