private void CalculateBounds(SecondDisplayProcess proc) { _thumbnail = LiveThumbnail.FromHandle(proc.Handle, this.Handle); Size size; if (_thumbnail != null && _thumbnail.IsValid && _thumbnail.SafeGetSize(out size)) { this.Height = Math.Min(size.Height, ThumbnailConstants.MaxHeight) + panelTitle.Top * 2 + ThumbnailConstants.ThumbPadding * 2; this.Width = Math.Min(size.Width, ThumbnailConstants.MaxWidth) + panelTitle.Left * 2 + ThumbnailConstants.ThumbPadding * 2; using (GraphicsPath gp = RoundedRectangle.Create(this.ClientRectangle, 5)) { Region hrgn = new System.Drawing.Region(gp); Graphics g = Graphics.FromHwnd(this.Handle); Native.SetWindowRgn(this.Handle, hrgn.GetHrgn(g), true); } } else { this.Height = 51; this.Width = panelTitle.Left * 2 + CalculateWidth(proc.Title.Clamp(Constants.MaxProgramNameLength)); using (GraphicsPath gp = new GraphicsPath()) { gp.AddRectangle(this.ClientRectangle); Region hrgn = new System.Drawing.Region(gp); Graphics g = Graphics.FromHwnd(this.Handle); Native.SetWindowRgn(this.Handle, hrgn.GetHrgn(g), true); } } }
public void Show(TaskbarButton button) { CancelHide(); PanelHover = true; if (button == _button) { return; } SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; _button = button; if (_thumbnail != null) { _thumbnail.Dispose(); _thumbnail = null; } CalculateBounds(proc); this.StartPosition = FormStartPosition.Manual; Rectangle parentBounds = button.Parent.RectangleToScreen(button.Bounds); Screen buttonScreen = proc.Screen; var taskbarLocation = TaskbarPropertiesManager.Instance.Properties.GetTaskbarLocation(buttonScreen.DeviceName); if (taskbarLocation == Native.ABEdge.Top || taskbarLocation == Native.ABEdge.Bottom) { int x = (parentBounds.Left + parentBounds.Width / 2) - this.Width / 2; if (x < buttonScreen.WorkingArea.Left) { x = buttonScreen.WorkingArea.Left; } if (x + this.Width > buttonScreen.WorkingArea.Right) { x = buttonScreen.WorkingArea.Right - this.Width; } int y = taskbarLocation == Native.ABEdge.Bottom ? (parentBounds.Top - this.Height) : parentBounds.Bottom; this.Location = new Point(x, y); } else { int x = taskbarLocation == Native.ABEdge.Left ? parentBounds.Right : (parentBounds.Left - this.Width); int y = (parentBounds.Top + parentBounds.Height / 2) - this.Height / 2; if (y < buttonScreen.WorkingArea.Top) { y = buttonScreen.WorkingArea.Top; } if (y + this.Height > buttonScreen.WorkingArea.Bottom) { y = buttonScreen.WorkingArea.Bottom - this.Height; } this.Location = new Point(x, y); } _buttonRectangle = new Rectangle(panelTitle.Width - ThumbnailConstants.IconMargin - ThumbnailConstants.CloseButWidth, 10, ThumbnailConstants.CloseButWidth, ThumbnailConstants.CloseButWidth); if (this.Visible) { this.Refresh(); } else { this.Visible = true; } _closeForm.Show(); Point location = panelTitle.PointToScreen(new Point(panelTitle.Width - ThumbnailConstants.IconMargin - ThumbnailConstants.CloseButWidth, 10)); _closeForm.Left = location.X; _closeForm.Top = location.Y; _closeForm.Draw(DualMonitor.Properties.Resources.close); ShowDefaultTooltip(); }