private void CustomWindow_StateChanged(object sender, EventArgs e) { if (WindowState == WindowState.Maximized) { var taskbar = new Interop.Taskbar(); if (taskbar.AutoHide) { var chrome = WindowChrome.GetWindowChrome(this); if (chrome != null) { chrome.NonClientFrameEdges = (NonClientFrameEdges)Enum.Parse(typeof(NonClientFrameEdges), taskbar.Position.ToString(), true); } } } }
public new void Show() { this.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual; this.Topmost = true; var cursorLocation = SWF.Cursor.Position; var waBounds = SWF.Screen.PrimaryScreen.WorkingArea; var scBounds = SWF.Screen.PrimaryScreen.Bounds; var cursorNearest32X = Nearest(cursorLocation.X); var cursorNearest32Y = Nearest(cursorLocation.Y); Interop.Taskbar tb = null; try { tb = new Interop.Taskbar(); } catch (InvalidOperationException) { this.Left = scBounds.Width - this.Width - DISPLAY_OFFSET; this.Top = scBounds.Height - this.Height - DISPLAY_OFFSET; } if ( tb.Position == Interop.Taskbar.TaskbarPosition.Bottom || tb.Position == Interop.Taskbar.TaskbarPosition.Top ) { // Get the window "near enough" the notification tray icon this.Left = (cursorNearest32X - this.Width / 2); // If we take the difference between how far left we are and // the location of the cursor, we somehow centre it over the // notification tray icon. // // See: http://xkcd.com/323/ this.Left += cursorLocation.X - this.Left - (this.Width / 2); if (this.Left + this.Width > scBounds.Width) this.Left = scBounds.Width - this.Width - DISPLAY_OFFSET; } else if ( tb.Position == Interop.Taskbar.TaskbarPosition.Left || tb.Position == Interop.Taskbar.TaskbarPosition.Right ) { this.Top = (cursorNearest32Y - this.Height / 2); this.Top += cursorLocation.Y - this.Top - (this.Height / 2); } if (tb.Position == Interop.Taskbar.TaskbarPosition.Bottom) { this.Top = scBounds.Height - (tb.Size.Height + DISPLAY_OFFSET + this.Height); } else if (tb.Position == Interop.Taskbar.TaskbarPosition.Top) { this.Top = tb.Size.Height + DISPLAY_OFFSET; } else if (tb.Position == Interop.Taskbar.TaskbarPosition.Right) { this.Left = scBounds.Width - this.Width - tb.Size.Width - DISPLAY_OFFSET; } else if (tb.Position == Interop.Taskbar.TaskbarPosition.Left) { this.Left = tb.Size.Width + DISPLAY_OFFSET; } base.Show(); base.Activate(); }