주 콘텐츠로 건너뛰기

 none
Using SetCompatibleTextRenderingDefault in VB RRS feed

  • 질문

  • 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.
    2009년 6월 4일 목요일 오전 1:42

답변

  • 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
    2009년 6월 5일 금요일 오전 5:36

모든 응답

  • 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
    2009년 6월 4일 목요일 오전 1: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.
    2009년 6월 4일 목요일 오전 1: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.
    2009년 6월 4일 목요일 오전 2:04
  • But not work for me, there was throwed InvalidOperationException.
    2009년 6월 4일 목요일 오전 2: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.
    2009년 6월 4일 목요일 오전 2:07
  • the full message is "在應用程式中建立第一個 IWin32Window 物件之前,必須先呼叫 SetCompatibleTextRenderingDefault。", stack trace is:
    > WindowsApplication1.exe!WindowsApplication1.Module1.Main() 行 9 Basic
      [外部程式碼] 
    2009년 6월 4일 목요일 오전 2:12
  • Please translate that text into English.  Thanks.
    2009년 6월 4일 목요일 오후 10: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
    2009년 6월 4일 목요일 오후 11: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.



    • 답변으로 표시됨 Tze Ying 2009년 6월 5일 금요일 오전 5:52
    2009년 6월 5일 금요일 오전 5:36
  • thank you very much.

    you help me to fix the problem now.
    2009년 6월 5일 금요일 오전 5:53