在Windows XP中设置GridGroupingControl的字体似乎是个问题。
以下是代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.autoLabel1.Font = new Font(Fonts.GetFontFamily(), 10f);
this.normalLabel.Font = new Font(Fonts.GetFontFamily(), 10f);
this.gridGroupingControl1.Font = new Font(Fonts.GetFontFamily(), 10f);
}
}
public static class Fonts
{
private static PrivateFontCollection pfc;
public static System.Drawing.FontFamily GetFontFamily()
{
try
{
if (pfc == null)
{
pfc = new PrivateFontCollection();
AddMemoryFont(Properties.Resources.OpenSans_Bold);
AddMemoryFont(Properties.Resources.OpenSans_BoldItalic);
AddMemoryFont(Properties.Resources.OpenSans_ExtraBold);
AddMemoryFont(Properties.Resources.OpenSans_ExtraBoldItalic);
AddMemoryFont(Properties.Resources.OpenSans_Italic);
AddMemoryFont(Properties.Resources.OpenSans_Light);
AddMemoryFont(Properties.Resources.OpenSans_LightItalic);
AddMemoryFont(Properties.Resources.OpenSans_Regular);
AddMemoryFont(Properties.Resources.OpenSans_Semibold);
AddMemoryFont(Properties.Resources.OpenSans_SemiboldItalic);
}
}
catch (Exception ex)
{
throw ex;
}
return pfc.Families.FirstOrDefault();
}
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
private static void AddMemoryFont(byte[] fontResource)
{
try
{
IntPtr p;
uint c = 0;
p = Marshal.AllocCoTaskMem(fontResource.Length);
Marshal.Copy(fontResource, 0, p, fontResource.Length);
AddFontMemResourceEx(p, (uint)fontResource.Length, IntPtr.Zero, ref c);
pfc.AddMemoryFont(p, fontResource.Length);
Marshal.FreeCoTaskMem(p);
p = IntPtr.Zero;
}
catch
{
throw;
}
}
}
当我在windows7上运行此应用程序时,在网格中显示正确的字体没有问题但是当在Windows XP上运行相同的应用程序时,网格中的字体实际上是默认的(MS Sans)。
编辑:当我用这个字体设置到其他syncfusion控件时,它工作正常。
如何解决他的问题?有没有办法做到这一点,还是我做错了什么?