C#Win Form App字体处理自动生成的代码 [英] C# Win Form App Font Disposal for auto generated code
问题描述
问候,我有一个带文本的C#窗体应用程序,字体代码显然是自动生成的,并放在Form.Designer.cs文件中。我被告知我需要确保字体正确处理,但由于它是自动生成的代码,我不确定如何去做。所以,我搜索并发现了这个:
你可以通过使用构造模式来控制Font的处理。在调用main中,您应该将Application包装在Form的using结构中。
示例:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMainUtility() );
到此:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
使用(FrmMainUtility form = new FrmMainUtility())
{
Application.Run(form);
}
这看起来对你不对吗?这是一种我可以用来完成字体清洁处理的技术吗?
我意识到有Dispose方法是标准做法,但我想知道上面的代码是否可以处理字体。
注意:我的应用程序已经过HP Fortify扫描。此示例取自:
http ://stackoverflow.com/questions/21769908/how-and-when-is-font-disposed-for-winforms-controls [ ^ ]
Greetings, I have a C# windows form application with text and the font code is apparently auto generated and placed in the Form.Designer.cs file. I've been told that I need to ensure the font is disposed correctly but since it is auto generated code, I am unsure as to how to go about it. So, I searched and found this:
You can control the disposal of Font by including in using construct pattern. In the calling main, you should wrap the Application inside the using construct of the Form.
Example:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMainUtility());
to this:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (FrmMainUtility form = new FrmMainUtility())
{
Application.Run(form);
}
Does this look correct to you? Is this a technique I can use to accomplish a clean disposal of the fonts?
I realize that there are Dispose methods that are standard practice, but I'd like to know if the above code works to dispose the fonts.
Note: My app has been subject to a HP Fortify scan. This example taken from :
http://stackoverflow.com/questions/21769908/how-and-when-is-font-disposed-for-winforms-controls[^]
推荐答案
在下面的链接中有一篇博客文章讨论类似问题:
http://blogs.msdn.com/b/ploeh/archive/2006/08/10/howtodisposemembersfromforms.aspx [ ^ ]
它描述了如何从表单中处理成员。在该帖子的评论部分,作者提供了以下代码和说明。
There is a blog post at below link discussing similar issue:
http://blogs.msdn.com/b/ploeh/archive/2006/08/10/howtodisposemembersfromforms.aspx[^]
It describes how to dispose Members From Forms. In the comments section of that post Author has provided below code with explanation.
public partial class MyForm : Form
{
private MyDisposable myDisposable_;
public MyForm()
{
InitializeComponent();
this.myDisposable_ =
new MyDisposable("Goodbye, World");
this.Disposed += new EventHandler(this.OnMyFormDisposed);
}
void OnMyFormDisposed(object sender, EventArgs e)
{
this.myDisposable_.Dispose();
}
}
下面的链接会有所帮助:
http://stackoverflow.com/questions/ 1052147 / how-do-i-extend-a-winforms-dispose-method [ ^ ]
http://blogs.msdn.com/b/jfoscoding/archive/2005/08/12/450835.aspx [ ^ ]
谢谢。
further below links would be helpful:
http://stackoverflow.com/questions/1052147/how-do-i-extend-a-winforms-dispose-method[^]
http://blogs.msdn.com/b/jfoscoding/archive/2005/08/12/450835.aspx[^]
Thanks.
这篇关于C#Win Form App字体处理自动生成的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!