private void WmMeasureMenuItem(ref Message m) { System.Windows.Forms.NativeMethods.MEASUREITEMSTRUCT lParam = (System.Windows.Forms.NativeMethods.MEASUREITEMSTRUCT)m.GetLParam(typeof(System.Windows.Forms.NativeMethods.MEASUREITEMSTRUCT)); MenuItem menuItemFromItemData = MenuItem.GetMenuItemFromItemData(lParam.itemData); if (menuItemFromItemData != null) { menuItemFromItemData.WmMeasureItem(ref m); } }
internal void WmMeasureItem(ref Message m) { System.Windows.Forms.NativeMethods.MEASUREITEMSTRUCT lParam = (System.Windows.Forms.NativeMethods.MEASUREITEMSTRUCT)m.GetLParam(typeof(System.Windows.Forms.NativeMethods.MEASUREITEMSTRUCT)); IntPtr dC = System.Windows.Forms.UnsafeNativeMethods.GetDC(System.Windows.Forms.NativeMethods.NullHandleRef); Graphics graphics = Graphics.FromHdcInternal(dC); MeasureItemEventArgs e = new MeasureItemEventArgs(graphics, this.Index); try { this.OnMeasureItem(e); } finally { graphics.Dispose(); } System.Windows.Forms.UnsafeNativeMethods.ReleaseDC(System.Windows.Forms.NativeMethods.NullHandleRef, new HandleRef(null, dC)); lParam.itemHeight = e.ItemHeight; lParam.itemWidth = e.ItemWidth; Marshal.StructureToPtr(lParam, m.LParam, false); m.Result = (IntPtr)1; }