protected override void OnRender(DrawingContext dc) { double dpiScaleX = VisualTreeHelper.GetDpi(this).DpiScaleX; double thickness = DPIHelper.RoundByPixelBound(ShadowThickness, dpiScaleX); double thickness2x = thickness + thickness; Rect rect = new Rect(thickness, thickness, RenderSize.Width - thickness2x, RenderSize.Height - thickness2x); dc.DrawRectangle(new SolidColorBrush(Colors.White), null, rect); Color baseColor = ShadowColor; double step = 1.0 / dpiScaleX; int thicknessInPixels = (int)Math.Round(ShadowThickness * dpiScaleX); for (int i = 0; i <= thicknessInPixels; i++) { double indent = i / dpiScaleX; double indent2x = indent + indent; rect = new Rect(indent, indent, Math.Max(0.0, RenderSize.Width - indent2x), Math.Max(0.0, RenderSize.Height - indent2x)); baseColor.A = (byte)Math.Round(minOpacity + (i * i) / growFactor); Pen pen = new Pen(new SolidColorBrush(baseColor), 1.0 / dpiScaleX); dc.DrawRoundedRectangle(null, pen, rect, dpiScaleX, dpiScaleX); } }
private void SetThreadDPI(DPIHelper.DPI_AWARENESS_CONTEXT newvalue, bool showMessage) { DPIHelper.DPI_AWARENESS_CONTEXT previous = DPIHelper.SetThreadDpiAwareness(newvalue); int processId = Process.GetCurrentProcess().Id; int threadId = Thread.CurrentThread.ManagedThreadId; if (showMessage) { MessageBox.Show(String.Format("DPI Awareness set to {0}, was {1}\nProcessId {2}, ThreadId {3}", newvalue, previous, processId, threadId)); } }
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) { double dpiScaleX = VisualTreeHelper.GetDpi(this).DpiScaleX; double thickness = DPIHelper.RoundByPixelBound(ShadowThickness, dpiScaleX); if (hitTestParameters.HitPoint.X <= thickness || hitTestParameters.HitPoint.X >= RenderSize.Width - thickness || hitTestParameters.HitPoint.Y <= thickness || hitTestParameters.HitPoint.Y >= RenderSize.Height - thickness) { return(null); } return(base.HitTestCore(hitTestParameters)); }
private void RefreshValues() { this.txtThreadAwareness.Text = DPIHelper.GetThreadDpiAwareness().ToString(); this.txtProcessAwareness.Text = DPIHelper.GetProcessDpi().ToString(); if (this.Handle != null) { Debug.WriteLine("Toplevel context window hwnd={0}", this.Handle); this.txtTaskpaneWindowAwareness.Text = DPIHelper.GetWindowDpiAwareness(this.Handle).ToString(); } this.txtHostWindowAwareness.Text = DPIHelper.GetWindowDpiAwareness((IntPtr)Globals.ThisAddIn.Application.Hwnd).ToString(); }
protected override Size ArrangeOverride(Size finalSize) { // arrange child UIElement child = Child; if (child != null) { double dpiScaleX = VisualTreeHelper.GetDpi(this).DpiScaleX; double thickness = DPIHelper.RoundByPixelBound(ShadowThickness, dpiScaleX); double thickness2x = thickness + thickness; double width = DPIHelper.RoundByPixelBound(finalSize.Width, dpiScaleX); double height = DPIHelper.RoundByPixelBound(finalSize.Height, dpiScaleX); Rect childRect = new Rect(thickness, thickness, Math.Max(0.0, width - thickness2x), Math.Max(0.0, height - thickness2x)); child.Arrange(childRect); } return(finalSize); }
protected override Size MeasureOverride(Size constraint) { double dpiScaleX = VisualTreeHelper.GetDpi(this).DpiScaleX; double thickness = DPIHelper.RoundByPixelBound(ShadowThickness, dpiScaleX); double thickness2x = thickness + thickness; UIElement child = Child; Size mySize = new Size(thickness2x, thickness2x); if (child != null) { Size childConstraint = new Size(Math.Max(0.0, constraint.Width - mySize.Width), Math.Max(0.0, constraint.Height - mySize.Height)); child.Measure(childConstraint); Size childSize = child.DesiredSize; mySize.Width += DPIHelper.RoundByPixelBound(childSize.Width, dpiScaleX); mySize.Height += DPIHelper.RoundByPixelBound(childSize.Height, dpiScaleX); } return(mySize); }
protected void WindowStateChanged(object sender, EventArgs e) { var w = ((Window)sender); var handle = w.GetWindowHandle(); var containerBorder = (Border)w.Template.FindName("WindowBorder", w); if (w.WindowState == WindowState.Maximized) { double dpiScaleX = VisualTreeHelper.GetDpi(w).DpiScaleX; double dpiScaleY = VisualTreeHelper.GetDpi(w).DpiScaleY; // Make sure window doesn't overlap with the taskbar. var screen = System.Windows.Forms.Screen.FromHandle(handle); containerBorder.Margin = new Thickness( DPIHelper.RoundByPixelBound(7 - 1, dpiScaleX), DPIHelper.RoundByPixelBound(7 - 1, dpiScaleY), DPIHelper.RoundByPixelBound((screen.Bounds.Width - screen.WorkingArea.Width) / dpiScaleX + 7 - 1, dpiScaleX), DPIHelper.RoundByPixelBound((screen.Bounds.Height - screen.WorkingArea.Height) / dpiScaleY + 7 - 1, dpiScaleY)); } else { containerBorder.Margin = new Thickness(0, 0, 0, 0); } }
private void Outlook_ItemSend(object Item, ref bool Cancel) { Microsoft.Office.Interop.Outlook.MailItem mail = Item as Microsoft.Office.Interop.Outlook.MailItem; if (mail != null) { MessageBox.Show(string.Format("ItemSend {0} with DpiThreadAwarenessContext {1}", mail.Subject, DPIHelper.GetThreadDpiAwarenessContext().ToString())); } }
private void Application_WorkbookBeforeSave(Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel) { MessageBox.Show(string.Format("WorkbookSave {0} with DpiThreadAwarenessContext {1}", Wb.Name, DPIHelper.GetThreadDpiAwarenessContext().ToString())); }
private void Application_WorkbookOpen(Excel.Workbook Wb) { MessageBox.Show(string.Format("WorkbookOpen {0} with DpiThreadAwarenessContext {1}", Wb.Name, DPIHelper.GetThreadDpiAwarenessContext().ToString())); }
private void Word_DocumentOpen(Microsoft.Office.Interop.Word.Document Doc) { MessageBox.Show(string.Format("DocumentOpen {0} with DpiThreadAwarenessContext {1}", Doc.ActiveWindow.Caption, DPIHelper.GetThreadDpiAwarenessContext().ToString())); }
private void btnSetCWMM_Click(object sender, EventArgs e) { DPIHelper.SetChildWindowMixedMode(DPIHelper.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_MIXED); MessageBox.Show(String.Format("DPI Hosting Behavior is {0}", DPIHelper.GetChildWindowMixedMode(this.Handle).ToString())); }
private void Visio_DocOpened(Microsoft.Office.Interop.Visio.Document doc) { MessageBox.Show(string.Format("DocOpened {0} with DpiThreadAwarenessContext {1}", doc.Name, DPIHelper.GetThreadDpiAwarenessContext().ToString())); }
private void PowerPoint_AfterOpen(Microsoft.Office.Interop.PowerPoint.Presentation pres) { MessageBox.Show(string.Format("PresentationAfterOpen {0} with DpiThreadAwarenessContext {1}", pres.Name, DPIHelper.GetThreadDpiAwarenessContext().ToString())); }