/// <summary> /// Handle DPI changes for the specified ContextMenuStrip /// </summary> /// <param name="contextMenuStrip">ContextMenuStrip</param> /// <returns>DpiHandler</returns> public static DpiHandler AttachDpiHandler(this ContextMenuStrip contextMenuStrip) { // Create a DpiHandler which runs "outside" of the contextMenu (not via WinProc) var dpiHandler = new DpiHandler(true); var listener = new WinProcListener(contextMenuStrip); listener.AddHook(dpiHandler.HandleContextMenuMessages); dpiHandler.MessageHandler = listener; return(dpiHandler); }
/// <summary> /// Handle DPI changes for the specified Form /// Using this DOES NOT enable dpi scaling in the non client area, for this you will need to call: /// DpiHandler.TryEnableNonClientDpiScaling(this.Handle) from the WndProc in the WM_NCCREATE message. /// It's better to extend DpiAwareForm, which does this for you. /// </summary> /// <param name="form">Control</param> /// <returns>DpiHandler</returns> public static DpiHandler AttachDpiHandler(this Form form) { // Create a DpiHandler which runs "outside" of the form (not via WinProc) var dpiHandler = new DpiHandler(true); var listener = new WinProcListener(form); listener.AddHook(dpiHandler.HandleWindowMessages); dpiHandler.MessageHandler = listener; return(dpiHandler); }