public static int GetTextMetrics(HandleRef hDC, ref System.Windows.Forms.NativeMethods.TEXTMETRIC lptm)
 {
     if (Marshal.SystemDefaultCharSize == 1)
     {
         System.Windows.Forms.NativeMethods.TEXTMETRICA textmetrica = new System.Windows.Forms.NativeMethods.TEXTMETRICA();
         int textMetricsA = GetTextMetricsA(hDC, ref textmetrica);
         lptm.tmHeight           = textmetrica.tmHeight;
         lptm.tmAscent           = textmetrica.tmAscent;
         lptm.tmDescent          = textmetrica.tmDescent;
         lptm.tmInternalLeading  = textmetrica.tmInternalLeading;
         lptm.tmExternalLeading  = textmetrica.tmExternalLeading;
         lptm.tmAveCharWidth     = textmetrica.tmAveCharWidth;
         lptm.tmMaxCharWidth     = textmetrica.tmMaxCharWidth;
         lptm.tmWeight           = textmetrica.tmWeight;
         lptm.tmOverhang         = textmetrica.tmOverhang;
         lptm.tmDigitizedAspectX = textmetrica.tmDigitizedAspectX;
         lptm.tmDigitizedAspectY = textmetrica.tmDigitizedAspectY;
         lptm.tmFirstChar        = (char)textmetrica.tmFirstChar;
         lptm.tmLastChar         = (char)textmetrica.tmLastChar;
         lptm.tmDefaultChar      = (char)textmetrica.tmDefaultChar;
         lptm.tmBreakChar        = (char)textmetrica.tmBreakChar;
         lptm.tmItalic           = textmetrica.tmItalic;
         lptm.tmUnderlined       = textmetrica.tmUnderlined;
         lptm.tmStruckOut        = textmetrica.tmStruckOut;
         lptm.tmPitchAndFamily   = textmetrica.tmPitchAndFamily;
         lptm.tmCharSet          = textmetrica.tmCharSet;
         return(textMetricsA);
     }
     return(GetTextMetricsW(hDC, ref lptm));
 }
 public static extern int GetTextMetricsW(HandleRef hDC, [In, Out] ref System.Windows.Forms.NativeMethods.TEXTMETRIC lptm);
 public virtual void PopupDialog(int row)
 {
     GridEntry gridEntryFromRow = this.GetGridEntryFromRow(row);
     if (gridEntryFromRow != null)
     {
         if ((this.dropDownHolder != null) && this.dropDownHolder.GetUsed())
         {
             this.CloseDropDown();
         }
         else
         {
             bool needsDropDownButton = gridEntryFromRow.NeedsDropDownButton;
             bool enumerable = gridEntryFromRow.Enumerable;
             bool needsCustomEditorButton = gridEntryFromRow.NeedsCustomEditorButton;
             if (enumerable && !needsDropDownButton)
             {
                 this.DropDownListBox.Items.Clear();
                 object propertyValue = gridEntryFromRow.PropertyValue;
                 object[] propertyValueList = gridEntryFromRow.GetPropertyValueList();
                 int num = 0;
                 IntPtr dC = System.Windows.Forms.UnsafeNativeMethods.GetDC(new HandleRef(this.DropDownListBox, this.DropDownListBox.Handle));
                 IntPtr handle = this.Font.ToHfont();
                 System.Internal.HandleCollector.Add(handle, System.Windows.Forms.NativeMethods.CommonHandles.GDI);
                 System.Windows.Forms.NativeMethods.TEXTMETRIC lptm = new System.Windows.Forms.NativeMethods.TEXTMETRIC();
                 int currentValueIndex = -1;
                 try
                 {
                     handle = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(this.DropDownListBox, dC), new HandleRef(this.Font, handle));
                     currentValueIndex = this.GetCurrentValueIndex(gridEntryFromRow);
                     if ((propertyValueList != null) && (propertyValueList.Length > 0))
                     {
                         IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
                         for (int i = 0; i < propertyValueList.Length; i++)
                         {
                             string propertyTextValue = gridEntryFromRow.GetPropertyTextValue(propertyValueList[i]);
                             this.DropDownListBox.Items.Add(propertyTextValue);
                             IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(this.DropDownListBox, dC), propertyTextValue, size);
                             num = Math.Max(size.cx, num);
                         }
                     }
                     System.Windows.Forms.SafeNativeMethods.GetTextMetrics(new HandleRef(this.DropDownListBox, dC), ref lptm);
                     num += (2 + lptm.tmMaxCharWidth) + SystemInformation.VerticalScrollBarWidth;
                     handle = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(this.DropDownListBox, dC), new HandleRef(this.Font, handle));
                 }
                 finally
                 {
                     System.Windows.Forms.SafeNativeMethods.DeleteObject(new HandleRef(this.Font, handle));
                     System.Windows.Forms.UnsafeNativeMethods.ReleaseDC(new HandleRef(this.DropDownListBox, this.DropDownListBox.Handle), new HandleRef(this.DropDownListBox, dC));
                 }
                 if (currentValueIndex != -1)
                 {
                     this.DropDownListBox.SelectedIndex = currentValueIndex;
                 }
                 this.SetFlag(0x40, false);
                 this.DropDownListBox.Height = Math.Max(lptm.tmHeight + 2, Math.Min(200, this.DropDownListBox.PreferredHeight));
                 this.DropDownListBox.Width = Math.Max(num, this.GetRectangle(row, 2).Width);
                 try
                 {
                     bool flag4 = this.DropDownListBox.Items.Count > (this.DropDownListBox.Height / this.DropDownListBox.ItemHeight);
                     this.SetFlag(0x400, flag4);
                     this.DropDownControl(this.DropDownListBox);
                 }
                 finally
                 {
                     this.SetFlag(0x400, false);
                 }
                 this.Refresh();
             }
             else if (needsCustomEditorButton || needsDropDownButton)
             {
                 try
                 {
                     this.SetFlag(0x10, true);
                     this.Edit.DisableMouseHook = true;
                     try
                     {
                         this.SetFlag(0x400, gridEntryFromRow.UITypeEditor.IsDropDownResizable);
                         gridEntryFromRow.EditPropertyValue(this);
                     }
                     finally
                     {
                         this.SetFlag(0x400, false);
                     }
                 }
                 finally
                 {
                     this.SetFlag(0x10, false);
                     this.Edit.DisableMouseHook = false;
                 }
                 this.Refresh();
                 if (this.FocusInside)
                 {
                     this.SelectGridEntry(gridEntryFromRow, false);
                 }
             }
         }
     }
 }
 private SizeF GetFontAutoScaleDimensions()
 {
     SizeF empty = SizeF.Empty;
     IntPtr handle = System.Windows.Forms.UnsafeNativeMethods.CreateCompatibleDC(System.Windows.Forms.NativeMethods.NullHandleRef);
     if (handle == IntPtr.Zero)
     {
         throw new Win32Exception();
     }
     HandleRef hDC = new HandleRef(this, handle);
     try
     {
         HandleRef hObject = new HandleRef(this, base.FontHandle);
         HandleRef ref4 = new HandleRef(this, System.Windows.Forms.SafeNativeMethods.SelectObject(hDC, hObject));
         try
         {
             System.Windows.Forms.NativeMethods.TEXTMETRIC lptm = new System.Windows.Forms.NativeMethods.TEXTMETRIC();
             System.Windows.Forms.SafeNativeMethods.GetTextMetrics(hDC, ref lptm);
             empty.Height = lptm.tmHeight;
             if ((lptm.tmPitchAndFamily & 1) != 0)
             {
                 IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
                 IntUnsafeNativeMethods.GetTextExtentPoint32(hDC, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", size);
                 empty.Width = (int) Math.Round((double) (((float) size.cx) / ((float) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".Length)));
                 return empty;
             }
             empty.Width = lptm.tmAveCharWidth;
             return empty;
         }
         finally
         {
             System.Windows.Forms.SafeNativeMethods.SelectObject(hDC, ref4);
         }
     }
     finally
     {
         System.Windows.Forms.UnsafeNativeMethods.DeleteCompatibleDC(hDC);
     }
     return empty;
 }