1 using System; // STAThread 2 using System.Windows.Forms; // Application and MessageBox objects 3 using System.Drawing; // Color 4 using System.Threading; // Mutex 5 6 namespace standardApplications 7 { 8 static class Program 9 { 10 11 // the main entry point for the application 12 // STA means single thread apartment 13 [STAThread] 14 static void Main() 15 { 16 bool ownsMutex; 17 Mutex myMutex = null; 18 try 19 { 20 // Mutex constructor sets ownsMutex to false if mutex already exists, 21 // or to true if a new mutex was just created 22 myMutex = new Mutex(false, Application.ProductName, out ownsMutex); 23 if (!ownsMutex) 24 { 25 MessageBox.Show 26 ( 27 Application.ProductName + " is already running." 28 ); 29 return; // do not allow this program to run twice 30 } 31 GC.KeepAlive(myMutex); 32 33 Application.EnableVisualStyles(); 34 Application.Run(new Form1()); 35 } 36 catch (Exception ex) 37 { 38 MessageBox.Show(ex.Message.ToString() + 39 "\r\n\r\nThis application will close."); 40 foreach (Form frm in Application.OpenForms) frm.Close(); 41 } 42 finally 43 { 44 // be sure and release Mutex before program exits 45 if (myMutex != null) myMutex.Close(); 46 Application.Exit(); 47 } 48 } 49 50 51 // ------------------- public properties ---------------- 52 53 54 // shortened product version for display in menus or window titles 55 public static string VersionShort 56 { 57 get 58 { 59 string stringMe = "Model.VersionShort: "; 60 try 61 { 62 string[] s = Application.ProductVersion.Split('.'); 63 string myStr = s[0] + "." + s[1]; 64 return myStr; 65 } 66 catch (Exception ex) 67 { 68 throw new Exception(stringMe + ex.Message); 69 } 70 } 71 set { ; } 72 } 73 74 75 public static int Form1Height 76 { 77 get { return Properties.Settings.Default.Form1Height; } 78 set 79 { 80 Properties.Settings.Default.Form1Height = value; 81 Properties.Settings.Default.Save(); 82 } 83 } 84 85 86 public static int Form1Width 87 { 88 get { return Properties.Settings.Default.Form1Width; } 89 set 90 { 91 Properties.Settings.Default.Form1Width = value; 92 Properties.Settings.Default.Save(); 93 } 94 } 95 96 97 public static int Form1Top 98 { 99 get { return Properties.Settings.Default.Form1Top; } 100 set 101 { 102 Properties.Settings.Default.Form1Top = value; 103 Properties.Settings.Default.Save(); 104 } 105 } 106 107 108 public static int Form1Left 109 { 110 get { return Properties.Settings.Default.Form1Left; } 111 set 112 { 113 Properties.Settings.Default.Form1Left = value; 114 Properties.Settings.Default.Save(); 115 } 116 } 117 118 119 public static bool Form1Maximized 120 { 121 get { return Properties.Settings.Default.Form1Maximized; } 122 set 123 { 124 Properties.Settings.Default.Form1Maximized = value; 125 Properties.Settings.Default.Save(); 126 } 127 } 128 129 130 public static Color Form1Backcolor 131 { 132 get { return Properties.Settings.Default.Form1Backcolor; } 133 set 134 { 135 Properties.Settings.Default.Form1Backcolor = value; 136 Properties.Settings.Default.Save(); 137 } 138 } 139 140 141 } 142 }