积极答复者
Using SetCompatibleTextRenderingDefault in VB

问题
-
Hi,
My question is I need to use Sub Main function to start my app in VB. But, the button property "UseCompatibleTextRendering" usually set to true after i started my app automatically. So, I want to use SetCompatibleTextRendering method to set the default value for the property "UseCompatibleTextRendering" of button.
How can I use SetCompatibleTextRenderingDefault method in Sub Main function since there was throwed InvalidOperationException.
Also, I readed msdn document about WindowsFormsApplicationBase.UseCompatibleTextRendering, but it should be enable Application Framework in project property. there was not support to set the app start from Sub Main.
I holp that you can understand my meaning. I will try to explain my idea to better.
答案
-
The following worked for me.
1. Start new VB.NET project.
2. Turn off Enable application framework. Choose to run Sub Main as the Startup object.
3. Add a Module file as follows:
Module Module1 Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Form) End Sub End Module
Are you running this program directly (not trying anything fancy that involves other code)?
Does your module have any variables that initialize like the following. This will cause problems because this New will happen prior to Sub Main:
Private ThisIsAProblem As New Form
Your process should not have created any windows or controls prior to the calling of SetCompatibleTextRenderingDefault.- 已标记为答案 Tze Ying 2009年6月5日 5:52
全部回复
-
Click Project, Your Project Properties, Application tab, View Application Events button.
Enter the following code:
Protected Overloads Shared ReadOnly Property UseCompatibleTextRendering() As Boolean Get Return True End Get End Property
This is described here: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.applicationservices.windowsformsapplicationbase.usecompatibletextrendering.aspx -
When Application Framework is disabled, the following code works for me:
Module Module1 Public Sub Main() Application.SetCompatibleTextRenderingDefault(True) Application.Run(New Form1) End Sub End Module
If you continue to have problems, please post full stack trace of the error. -
But not work for me, there was throwed InvalidOperationException.
-
ok, I think the meaning is "Call SetCompatibleTextRenderingDefault before the application create the object IWin32Window."
stack trace is:> WindowsApplication1.exe!WindowsApplication1.Module1.Main() Line:9 Basic
This is my code:
Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) 'a.Parent = New Areo.UIComponents.AreoWizard Application.Run(a.ShowWizard) End Sub
-
The following worked for me.
1. Start new VB.NET project.
2. Turn off Enable application framework. Choose to run Sub Main as the Startup object.
3. Add a Module file as follows:
Module Module1 Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Form) End Sub End Module
Are you running this program directly (not trying anything fancy that involves other code)?
Does your module have any variables that initialize like the following. This will cause problems because this New will happen prior to Sub Main:
Private ThisIsAProblem As New Form
Your process should not have created any windows or controls prior to the calling of SetCompatibleTextRenderingDefault.- 已标记为答案 Tze Ying 2009年6月5日 5:52