/// <summary> /// Calculate client position of control in window /// </summary> /// <param name="win"></param> /// <param name="control"></param> /// <returns></returns> static Point getClientLocation(mainWin win, Control control) { Control c = control.Parent; Point loc = control.Location; while (c.Parent != win) { loc.X += c.Location.X + c.Margin.Left; loc.Y += c.Location.Y + c.Margin.Top; c = c.Parent; } return(loc); }
/// <summary> /// Resize window to fit content /// </summary> /// <param name="win"></param> /// <param name="controls"></param> public static void apply(mainWin win, Control[] controls) { int winW = win.Width , newW = 0 , maxW = Screen.PrimaryScreen.WorkingArea.Width //, winH = win.Height //, newH = 0 //, maxH = Screen.PrimaryScreen.WorkingArea.Height ; Point location; foreach (Control control in controls) { location = getClientLocation(win, control); newW = Math.Max(location.X * 2 + control.Width, newW); //newH = Math.Max(location.Y * 2 + control.Height, newH); } newW = Math.Min(newW, maxW); //newH = Math.Min(newH, maxH); win.ClientSize = new Size(newW, win.ClientSize.Height); }
static void Main(string[] args) { log.Info("/***************************************************/"); log.Info("/ /"); log.Info(appInitString); log.Info("/ /"); log.Info("/***************************************************/"); Directory.CreateDirectory(tempDir); Directory.CreateDirectory(tempDnDir); //Console.WriteLine("Pipe.isAvailable: = {0}", Pipe.isAvailable()); //Pipe.PrintersClient(); //Console.WriteLine("Pipe.isAvailable 1"); //Pipe.isAvailable((f) => Console.WriteLine("Pipe.isAvailable result: {0}", f)); //Console.WriteLine("Pipe.isAvailable 2"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit); if (args != null && args.Length == 1 && args[0].Length > 1 && (args[0][0] == '-' || args[0][0] == '/')) { //MessageBox.Show(args.Length.ToString() + " " + args[0].Substring(1).ToLower()); switch (args[0].Substring(1).ToLower()) { case "silent": case "s": //MessageBox.Show("silent"); Program.isSilent = true; break; default: Console.WriteLine("Unrecognized parameters.\n\n -s /s -silent /silent — start minimized with tray icon"); return; } } Program.window = new mainWin(); Application.Run(Program.window); //else //{ // try // { // //AppDomain.CurrentDomain.ProcessExit += (sender, e) => cpamon.stop(); // //cpamon.run(); // } // catch (IOException ex) // { // //log.Error("", ex); // Console.WriteLine("IOException", ex); // //cpamon.stop(); // } // catch (Exception ex) // { // //log.Fatal("Could not start polling service due to unknown error", ex); // Console.WriteLine("Could not start programm due application error", ex); // //cpamon.stop(); // } //} }