[RESOLVED] [2008] Need Enable Application Framework but starting from Sub Main.
I've had a problem with a form that I use that is accessed using ShowDialog that has a bunch of labels that have large amounts of text on them. On those labels that have 20 or more lines of text on them the line spacing starts to wander away from that that you see when you're in the editor creating the text. I traced the problem to not having Enable Application Framework checked because I created a little miniprogram to try to solve the problem.
The project I'm working on starts from a module with a Sub Main that has the code :
Code:
Public mainForm As Form
Sub main()
mainForm = New DisplayGraphics
Do
Application.Run(mainForm)
Loop While Not mainForm Is Nothing
End Sub
This is for the purpose of swithcing between forms in my application.
Is there a way I can manually enable the application framework after starting from Sub Main. Or perhaps I should abandon the approach I'm using to swithch between forms and start from a form so that I can have Enable Application Framework checked. I'd have to learn another way to switch between forms.
Another possibility is that there is something that enable application framework does that eliminates my line spacing problem that I could do without enabling application framework.
Re: [2008] Need Enable Application Framework but starting from Sub Main.
Try this
Application.EnableVisualStyles()
Re: [2008] Need Enable Application Framework but starting from Sub Main.
Thanks for the response. I tried it but unfortunately it didn't work.
I attached two screenshots that show the problem I'm fixing by having the Enable Application Framework box checked. When the line spacing is off that's when I'm starting from Sub Main and I don't have the box for Enable Application Framework checked. When the line spacing is like it should be I'm starting from a form and not Sub Main and I can then check the box to enable Application Framework.
What else does enabling Application Framework do besides enabling Visual Styles? There should be some way I can get the line spacing like it's supposed to be without enabling Application Framework or else a way of enabling Application Framework after starting from Sub Main.
Re: [2008] Need Enable Application Framework but starting from Sub Main.
Try adding EnableVisualStyles as the first line of code in your submain procedure followed by a DoEvents. EnableVisualStyles is required as the first line of code to be executed before any form or control creation.
Re: [2008] Need Enable Application Framework but starting from Sub Main.
Before your response RobDog I had tried putting Application.EnableVisualStyles() in the form load sub for the first form that loads and I even tried putting in the two other forms in my experimental application. That didn't work.
After I read your response I tried this in my sub main
Code:
Public mainForm As Form
Sub main()
Application.EnableVisualStyles()
Application.DoEvents()
mainForm = New FormStart
Do
Application.Run(mainForm)
Loop While Not mainForm Is Nothing
End Sub
That didn't change anything so I also tried putting Application.DoEvents() after Application.EnableVisualStyles() in the load form subs and still no change.
It seems that it is likely something other than EnableVisualStyles that is eliminating the line spacing problem when I start from a form instead of sub main and have the enable application framework box checked.
Re: [2008] Need Enable Application Framework but starting from Sub Main.
If you place it in a forms new constructor its too late as the object is already created. If nothing changes in your Sub Main as I recommended then there may be other rendering benefits that visualstyles provides but not sure what other then perhaps SetTextRenderingHint.
Re: [2008] Need Enable Application Framework but starting from Sub Main.
I may have not been clear in some of my statements. I was trying to say that having enable Application Framework checked is definitely fixing my line spacing problem with labels but perhapse it isn't because it enables VisualStyles. I've confirmed that this is the case
The little miniprogram that I created to test how labels display I set to start from the form that has the labels and not sub main so I could check the box for enable Application Framework. In the properties box Windows Application Framework I unchecked the box to enable XP visual styles. When I ran the program the line spacing problem wasn't there which means that it is something else that enabling Application Framework is doing that fixes my line spacing problem or shall I say that keeps my line spacing problem from happening. I need to find out just what it is doing so I can do it manually without enabling Application Framework.
Re: [2008] Need Enable Application Framework but starting from Sub Main.
I was looking at all the properties you can adjust for labels and found that UseCompatibleTextRendering was set to False for all my labels. When I set it to true my problem was fixed. The line spacing that I saw in the editor and what I saw when I run my application matched.
The spacing was actually the same as before but you would see in the editor what you would get when you run your program so you can play around with things and know your result.
When I switch UseCompatibleTextRendering to True I see the text not going down as far on my labels. I found I can adjust the font size very slightly by setting font to 10.1 instead of 9.75. This gives me a result where the line spacing matches better with those labels that have UseCompatibleTextRendering set to False. I have a large number of labels so I probably won't change all the False settings to True. The labels that have less than about 15 lines of text, which is most of them, I'll leave as they were.
When selecting font size if I select 10 and click OK the result is 9.75. You can adjust that manually with the cursor.