code_junkie

Hide form at launch

Nov 14th, 2011
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. this.Hide();
  2. this.Visible = false;
  3.  
  4. BeginInvoke(new MethodInvoker(delegate
  5. {
  6. Hide();
  7. }));
  8.  
  9. // In Your Program.cs Convert This
  10. static void Main()
  11. {
  12. Application.EnableVisualStyles();
  13. Application.SetCompatibleTextRenderingDefault(false);
  14. Application.Run(new Form1());
  15. }
  16.  
  17. // To This
  18. static void Main()
  19. {
  20. Application.EnableVisualStyles();
  21. Application.SetCompatibleTextRenderingDefault(false);
  22. Form1 TheForm = new Form1();
  23. Application.Run();
  24. }
  25.  
  26. // Call Application.Exit() From Anywhere To Stop Application.Run() Message Pump and Exit Application
  27.  
  28. [STAThread]
  29. static void Main()
  30. {
  31. Application.EnableVisualStyles ();
  32. Application.SetCompatibleTextRenderingDefault (false);
  33. Application.Run (new MainForm ());
  34. }
  35.  
  36. static class Program {
  37. internal static Boolean UserExitCalled;
  38.  
  39. /// <summary>
  40. /// The main entry point for the application.
  41. /// </summary>
  42. [STAThread]
  43. static void Main() {
  44. Application.EnableVisualStyles();
  45. Application.SetCompatibleTextRenderingDefault(false);
  46.  
  47. // Setup your tray icon here
  48.  
  49. while (!UserExitCalled) {
  50. Application.DoEvents(); // Process windows messages
  51. Thread.Sleep(1);
  52. }
  53.  
  54. return;
  55. }
  56. }
  57.  
  58. // *********************************************************************
  59. // [DCOM Productions .NET]
  60. // [DPDN], [Visual Studio Launcher]
  61. //
  62. // THIS FILE IS PROVIDED "AS-IS" WITHOUT ANY WARRANTY OF ANY KIND. ANY
  63. // MODIFICATIONS TO THIS FILE IN ANY WAY ARE YOUR SOLE RESPONSIBILITY.
  64. //
  65. // [Copyright (C) DCOM Productions .NET All rights reserved.]
  66. // *********************************************************************
  67.  
  68. namespace VisualStudioLauncher
  69. {
  70. using System;
  71. using System.Collections.Generic;
  72. using System.Linq;
  73. using System.Windows.Forms;
  74. using System.Threading;
  75. using VisualStudioLauncher.Common.Objects;
  76. using VisualStudioLauncher.Forms;
  77. using System.Drawing;
  78. using VisualStudioLauncher.Common.Data;
  79. using System.IO;
  80. static class Program
  81. {
  82. #region Properties
  83.  
  84. private static ProjectLocationList m_ProjectLocationList;
  85. /// <summary>
  86. /// Gets or Sets the ProjectsLocationList
  87. /// </summary>
  88. public static ProjectLocationList ProjectLocationList
  89. {
  90. get
  91. {
  92. return m_ProjectLocationList;
  93. }
  94.  
  95. set
  96. {
  97. m_ProjectLocationList = value;
  98. }
  99. }
  100.  
  101. private static ShellProcessList m_ShellProcessList = null;
  102. /// <summary>
  103. /// Gets or Sets the ShellProcessList
  104. /// </summary>
  105. public static ShellProcessList ShellProcessList
  106. {
  107. get
  108. {
  109. return m_ShellProcessList;
  110. }
  111.  
  112. set
  113. {
  114. m_ShellProcessList = value;
  115. }
  116. }
  117.  
  118. private static NotifyIcon m_TrayIcon;
  119. /// <summary>
  120. /// Gets the programs tray application.
  121. /// </summary>
  122. public static NotifyIcon TrayIcon
  123. {
  124. get
  125. {
  126. return m_TrayIcon;
  127. }
  128. }
  129.  
  130. private static bool m_UserExitCalled;
  131. /// <summary>
  132. /// Gets a value indicating whether the user has called for an Application.Exit
  133. /// </summary>
  134. public static bool UserExitCalled
  135. {
  136. get
  137. {
  138. return m_UserExitCalled;
  139. }
  140.  
  141. set
  142. {
  143. m_UserExitCalled = value;
  144. }
  145. }
  146.  
  147. // TODO: Finish implementation, then use this for real.
  148. private static ApplicationConfiguration m_ApplicationConfiguration = null;
  149. /// <summary>
  150. /// Gets the application configuration
  151. /// </summary>
  152. public static ApplicationConfiguration ApplicationConfiguration
  153. {
  154. get
  155. {
  156. if (m_ApplicationConfiguration == null)
  157. m_ApplicationConfiguration = ApplicationConfiguration.LoadConfigSection(@"./settings.config");
  158.  
  159. return m_ApplicationConfiguration;
  160. }
  161. }
  162.  
  163.  
  164. #endregion
  165.  
  166. /// <summary>
  167. /// The main entry point for the application.
  168. /// </summary>
  169. [STAThread]
  170. static void Main(string[] args)
  171. {
  172. if (args.Length > 0)
  173. {
  174. if (args[0].ToLower() == "-rmvptr")
  175. {
  176. for (int i = 1; i < args.Length; i++) {
  177. try {
  178. if (File.Exists(Application.StartupPath + @"\" + args[i])) {
  179. File.Delete(Application.StartupPath + @"\" + args[i]);
  180. }
  181. }
  182. catch { /* this isn't critical, just convenient */ }
  183. }
  184. }
  185. }
  186.  
  187. Application.EnableVisualStyles();
  188. Application.SetCompatibleTextRenderingDefault(false);
  189.  
  190. SplashForm splashForm = new SplashForm();
  191. splashForm.Show();
  192.  
  193. while (!UserExitCalled)
  194. {
  195. Application.DoEvents();
  196. Thread.Sleep(1);
  197. }
  198.  
  199. if (m_TrayIcon != null)
  200. {
  201. m_TrayIcon.Icon = null;
  202. m_TrayIcon.Visible = false;
  203. m_TrayIcon.Dispose();
  204.  
  205. GC.Collect();
  206. }
  207. }
  208.  
  209. #region System Tray Management
  210.  
  211. public static void SetupTrayIcon()
  212. {
  213. m_TrayIcon = new NotifyIcon();
  214. m_TrayIcon.Text = Resources.UserInterfaceStrings.ApplicationName;
  215. m_TrayIcon.Visible = false; // This will be set visible when the context menu is generated
  216. m_TrayIcon.MouseDoubleClick += new MouseEventHandler(m_TrayIcon_MouseDoubleClick);
  217.  
  218. if (Orcas.IsInstalled)
  219. {
  220. m_TrayIcon.Icon = Orcas.Icon;
  221. }
  222. else if (Whidbey.IsInstalled) {
  223. m_TrayIcon.Icon = Whidbey.Icon;
  224. }
  225. else {
  226. m_TrayIcon.Icon = SystemIcons.Warning;
  227. m_TrayIcon.Text = "Visual Studio is not installed. VSL cannot run properly.";
  228. }
  229. }
  230.  
  231. static void m_TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
  232. {
  233. if (e.Button != MouseButtons.Left)
  234. {
  235. return;
  236. }
  237.  
  238. SettingsForm settingsForm = new SettingsForm();
  239. settingsForm.Show();
  240. }
  241.  
  242. #endregion
  243. }
Add Comment
Please, Sign In to add comment