/// <summary>Default constructor.</summary> protected TitleBarTabs() { _previousWindowState = null; ExitOnLastTabClose = true; AutoCreateTab = true; AutoCloseTab = true; InitializeComponent(); SetWindowThemeAttributes(WTNCA.NODRAWCAPTION | WTNCA.NODRAWICON); _tabs.CollectionModified += _tabs_CollectionModified; // Set the window style so that we take care of painting the non-client area, a redraw is triggered when the size of the window changes, and the // window itself has a transparent background color (otherwise the non-client area will simply be black when the window is maximized) SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); if (Environment.OSVersion.Version.Major >= 6) { SetProcessDPIAware(); } Tooltip = new ToolTip { AutoPopDelay = 5000, AutomaticDelay = 500 }; ShowTooltips = true; }
/// <summary> /// Requires no special permissions, because current used have full access to CurrentUser 'Run' registry key. /// </summary> /// <param name="enabled">Start with Windows after Sign-In.</param> /// <param name="startState">Start Mode.</param> public void UpdateWindowsStartRegistry(bool enabled, FormWindowState?startState = null) { startState = startState ?? SettingsManager.Options.StartWithWindowsState; var runKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (enabled) { // Add the value in the registry so that the application runs at start-up string command = string.Format("\"{0}\" /{1}={2}", Application.ExecutablePath, Program.arg_WindowState, startState.ToString()); var value = (string)runKey.GetValue(Application.ProductName); if (value != command) { runKey.SetValue(Application.ProductName, command); } } else { // Remove the value from the registry so that the application doesn't start if (runKey.GetValueNames().Contains(Application.ProductName)) { runKey.DeleteValue(Application.ProductName, false); } } runKey.Close(); }
/// <summary> /// 引发 <see cref="E:System.Windows.Forms.Control.SizeChanged"/> 事件。 /// </summary> /// <param name="e">包含事件数据的 <see cref="T:System.EventArgs"/>。</param> protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); if (_prevState != WindowState) { _prevState = WindowState; OnIsWindowVisibleChanged(); } }
/// <summary> /// Overrides the <see cref="Control.SizeChanged" /> handler so that we can detect when the user has maximized or restored the window and adjust the size /// of the non-client area accordingly. /// </summary> /// <param name="e">Arguments associated with the event.</param> protected override void OnSizeChanged(EventArgs e) { // If no tab renderer has been set yet or the window state hasn't changed, don't do anything if (_previousWindowState != null && WindowState != _previousWindowState.Value) { SetFrameSize(); } _previousWindowState = WindowState; base.OnSizeChanged(e); }
/// <summary>Default constructor.</summary> protected TitleBarTabs() { _previousWindowState = null; ExitOnLastTabClose = true; InitializeComponent(); SetWindowThemeAttributes(WTNCA.NODRAWCAPTION | WTNCA.NODRAWICON); _tabs.CollectionModified += _tabs_CollectionModified; // Set the window style so that we take care of painting the non-client area, a redraw is triggered when the size of the window changes, and the // window itself has a transparent background color (otherwise the non-client area will simply be black when the window is maximized) SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); }
private void MainForm_Resize(object sender, EventArgs e) { // Track window state changes. lock (lastStateLock) { var newWindowState = WindowState; if (!oldWindowState.HasValue || oldWindowState.Value != newWindowState) { oldWindowState = newWindowState; UpdateStatusBar(newWindowState); } } }
private void MainForm_Resize(object sender, EventArgs e) { // Track window state changes. lock (windowStateLock) { var newWindowState = WindowState; if (!oldWindowState.HasValue || oldWindowState.Value != newWindowState) { oldWindowState = newWindowState; // If window was minimized. if (newWindowState == FormWindowState.Minimized) { MinimizeToTray(false, SettingsManager.Options.MinimizeToTray); } } } }
public static StartupArguments Parse(IEnumerable <string> args) { Guard.NotNull(args, nameof(args)); string? path = null; Point? location = null; Size? size = null; FormWindowState?state = null; bool? transparentOnTop = null; foreach (string arg in args) { if (arg.StartsWith("pos=", StringComparison.OrdinalIgnoreCase)) { location = ParseLocation(arg.Substring("pos=".Length)); } if (arg.StartsWith("size=", StringComparison.OrdinalIgnoreCase)) { size = ParseSize(arg.Substring("size=".Length)); } else if (arg.StartsWith("state=", StringComparison.OrdinalIgnoreCase)) { state = ParseWindowState(arg.Substring("state=".Length)); } else if (string.Compare(arg, "transparentOnTop", StringComparison.OrdinalIgnoreCase) == 0) { transparentOnTop = true; } else if (!arg.Contains('=', StringComparison.Ordinal)) { if (path != null) { throw new InvalidOperationException("Multiple paths are not supported."); } path = arg; } } return(new StartupArguments(path, location, size, state ?? FormWindowState.Normal, transparentOnTop == true)); }
private void MainForm_Resize(object sender, EventArgs e) { // Track window state changes. lock (windowStateLock) { var newWindowState = WindowState; if (!oldWindowState.HasValue || oldWindowState.Value != newWindowState) { oldWindowState = newWindowState; // If window was minimized. if (newWindowState == FormWindowState.Minimized) { MinimizeToTray(false, SettingsManager.Options.MinimizeToTray); } } // Form GUI update is very heavy on CPU. // Enable form GUI update only if form is not minimized. EnableFormUpdates(WindowState != FormWindowState.Minimized && !Program.IsClosing); } }
// Ativa o formulario enviado por parametro no MDI pai public static void StartForm(Form form, Form mdiParent, FormWindowState?state) { // Verifica se o parente é null, se for null impede o usuário de usar outras telas sem antes finalizar a form. if (mdiParent == null) { form.ShowDialog(); return; } bool formAlreadyOpen = false; foreach (Form f in Application.OpenForms) { if (f.Name == form.Name) { formAlreadyOpen = true; f.WindowState = FormWindowState.Normal; f.BringToFront(); break; } } if (!formAlreadyOpen) { if (state != null) { form.WindowState = state.Value; } else { form.WindowState = FormWindowState.Minimized; } form.MdiParent = mdiParent; form.Top = 0; form.Left = 0; form.Show(); } }
private void MainForm_Resize(object sender, EventArgs e) { // When window state changes if (WindowState != LastWindowState) { if (WindowState == FormWindowState.Minimized) { // Minimized // set working controls to property values and start timer FotoTimer.Interval = Properties.Settings.Default.TimerInterval * 1000; // input in seconds interval in milli seconds PathToStore = Properties.Settings.Default.PathToStore; FotoTimer.Start(); } else { // Window is restored or maximized // stop timer and set input controls FotoTimer.Stop(); RefreshInputBoxes(); } LastWindowState = WindowState; } }
protected override void WndProc(ref Message m) { FormWindowState?newWindowState = null; if (m.Msg == WinUserConstants.WmSysCommand) { int wParam = m.WParam.ToInt32() & 0xFFF0; if (wParam == WinUserConstants.ScMinimize || wParam == WinUserConstants.ScMaximize || wParam == WinUserConstants.ScRestore) { newWindowState = TranslateWindowState(wParam); } } if (newWindowState != null) { EventHandler <WindowStateChangingEventArgs>?eventHandler = WindowStateChanging; if (eventHandler != null) { var args = new WindowStateChangingEventArgs(newWindowState.Value); eventHandler(this, args); if (args.Cancel) { return; } } } base.WndProc(ref m); if (newWindowState != null) { WindowStateChanged?.Invoke(this, EventArgs.Empty); } }
private void UI_CoreForm_Resize(object sender, EventArgs e) { // When window state changes if (WindowState != LastWindowState) { /* * if (WindowState == FormWindowState.Maximized) * { * // Maximized! * } * if (WindowState == FormWindowState.Normal) * { * // Restored! * } */ if (cfForm.spForm != null) { cfForm.spForm?.Parent_ResizeEnd(); } LastWindowState = WindowState; } }
public void Remember() { var form = _form; if (form == null) { throw new InvalidOperationException(); } var bounds = FormBoundsFromWindowState(form); if (bounds != null) { if (!IsOnScreen(bounds.Value.Location, bounds.Value.Size)) { return; } Location = bounds.Value.Location; Size = bounds.Value.Size; } WindowState = form.WindowState; }
public void Remember() { var form = _form; if (form == null) throw new InvalidOperationException(); var bounds = FormBoundsFromWindowState(form); if (bounds != null) { if (!IsOnScreen(bounds.Value.Location, bounds.Value.Size)) return; Location = bounds.Value.Location; Size = bounds.Value.Size; } WindowState = form.WindowState; }
protected override void Read() { FormWindowState?formWindowState = null; string windowState = ControlPreferences.GetValue(Name, "State"); if (windowState != null) { formWindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), windowState); } bool sizable = _form.FormBorderStyle == FormBorderStyle.Sizable || _form.FormBorderStyle == FormBorderStyle.SizableToolWindow; string xs = ControlPreferences.GetValue(Name, "X"); string ys = ControlPreferences.GetValue(Name, "Y"); string widths = ControlPreferences.GetValue(Name, "Width"); string heights = ControlPreferences.GetValue(Name, "Height"); if (xs != null && ys != null) { int x = int.Parse(xs, Culture); int y = int.Parse(ys, Culture); int width; int height; if (x < -30000) { x = 50; } if (y < -30000) { y = 0; } if (sizable && widths != null && heights != null) { width = int.Parse(widths, Culture); height = int.Parse(heights, Culture); } else { width = _form.Width; height = _form.Height; } System.Drawing.Rectangle formBounds = new System.Drawing.Rectangle(x, y, width, height); if (this.IsRectangleVisible(formBounds)) { _form.DesktopBounds = formBounds; if (_form.WindowState == FormWindowState.Normal) { User.SetWindowPos (_form.Handle, IntPtr.Zero, x + SystemInformation.WorkingArea.X, y + SystemInformation.WorkingArea.Y, width, height , SetWindowPosOptions.SWP_NOSIZE); } } } if (formWindowState != null) { SetWindowState(_form, formWindowState.Value); } else { SetWindowDefaultState(_form); } }
/// <summary> /// Overrides the <see cref="Control.SizeChanged" /> handler so that we can detect when the user has maximized or restored the window and adjust the size /// of the non-client area accordingly. /// </summary> /// <param name="e">Arguments associated with the event.</param> protected override void OnSizeChanged(EventArgs e) { // If no tab renderer has been set yet or the window state hasn't changed, don't do anything if (_previousWindowState != null && WindowState != _previousWindowState.Value) SetFrameSize(); _previousWindowState = WindowState; base.OnSizeChanged(e); }