Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在没有安装的情况下,如何在winform designer中使用ttf字体?_C#_Winforms - Fatal编程技术网

C# 在没有安装的情况下,如何在winform designer中使用ttf字体?

C# 在没有安装的情况下,如何在winform designer中使用ttf字体?,c#,winforms,C#,Winforms,我想在winform designer中使用自定义ttf字体。 我试图搜索,但是,只有通过编程方式添加。 但编程方式并没有反映在designer中。 wpf项目可以通过blend for visual studio实现这一点,但winform无法设置ttf字体,我使用designer将其添加到项目中。 我该怎么办?试试这个 // specify embedded resource name string resource = "embedded_font.PAGAP___.TTF"; // r

我想在winform designer中使用自定义ttf字体。 我试图搜索,但是,只有通过编程方式添加。 但编程方式并没有反映在designer中。 wpf项目可以通过blend for visual studio实现这一点,但winform无法设置ttf字体,我使用designer将其添加到项目中。 我该怎么办?

试试这个

// specify embedded resource name
string resource = "embedded_font.PAGAP___.TTF";

// receive resource stream
Stream fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);

// create an unsafe memory block for the font data
System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);

// create a buffer to read in to
byte[] fontdata = new byte[fontStream.Length];

// read the font data from the resource
fontStream.Read(fontdata, 0, (int)fontStream.Length);

// copy the bytes to the unsafe memory block
Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);

// pass the font to the font collection
private_fonts.AddMemoryFont(data, (int)fontStream.Length);

// close the resource stream
fontStream.Close();

// free up the unsafe memory
Marshal.FreeCoTaskMem(data);

如果未安装,设计师如何知道它的存在以便能够使用它?设计师使用它的来源是什么?使用一些常识。您的代码可以在应用程序启动时加载,从而使其可用于您的应用程序。如果未安装,设计器从何处加载?它怎么知道它在那里?我不知道这是否有用。你应该先搜索再发布@肯·怀特:我写这个项目的时候有一个字体。但是我在发布项目时发现了字体问题。所以我删除了我使用这个项目的ttf字体。@chopperfield我已经使用了PrivateFontCollection。但是ttf字体没有显示在designer中。所以你的问题是如何在designer中使用我删除的字体?现在这没有什么意义。不能使用设计器中不存在的字体。我不知道你为什么不明白。如果设计师不知道该字体,则不能使用该字体。如果你删除了它,不仅设计师不能使用它,你的应用程序也不能使用它。