none
Using SetCompatibleTextRenderingDefault in VB RRS feed

  • Pergunta

  • 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.
    quinta-feira, 4 de junho de 2009 01:42

Respostas

  • 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.



    • Marcado como Resposta Tze Ying sexta-feira, 5 de junho de 2009 05:52
    sexta-feira, 5 de junho de 2009 05:36

Todas as Respostas

  • 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
    quinta-feira, 4 de junho de 2009 01:51
  • BinaryCoder,

    If I use ApplicationEvents that I need to enable Application Framework. In this case, I can't to select the app start from Sub Main.
    quinta-feira, 4 de junho de 2009 01:54
  • 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.
    quinta-feira, 4 de junho de 2009 02:04
  • But not work for me, there was throwed InvalidOperationException.
    quinta-feira, 4 de junho de 2009 02:06
  • Like I said, please post the full message and stack trace of this error.

    Be sure that this is the first thing that you do in Main and that the Application Framework check box is turned off in the Project properties.
    quinta-feira, 4 de junho de 2009 02:07
  • the full message is "在應用程式中建立第一個 IWin32Window 物件之前,必須先呼叫 SetCompatibleTextRenderingDefault。", stack trace is:
    > WindowsApplication1.exe!WindowsApplication1.Module1.Main() 行 9 Basic
      [外部程式碼] 
    quinta-feira, 4 de junho de 2009 02:12
  • Please translate that text into English.  Thanks.
    quinta-feira, 4 de junho de 2009 22:24
  • 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
    quinta-feira, 4 de junho de 2009 23:33
  • 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.



    • Marcado como Resposta Tze Ying sexta-feira, 5 de junho de 2009 05:52
    sexta-feira, 5 de junho de 2009 05:36
  • thank you very much.

    you help me to fix the problem now.
    sexta-feira, 5 de junho de 2009 05:53