Form layout at runtime differs from design
-
Hi, When I use the code below to open the form 'MainForm', the text position on buttons and labels differs slightly from the position in the designer. For some labels the text is displayed on two lines, while the text fits exactly on one line in the form designer. If I do not define a Sub Main, but set the MainForm as Startup form, the form shows correctly. Has anyone an idea what could be the cause of this strange behaviour? Shared Sub main() Application.EnableVisualStyles() Application.DoEvents() Application.Run(MainForm) End Sub Thanks, Marc
-
Hi, When I use the code below to open the form 'MainForm', the text position on buttons and labels differs slightly from the position in the designer. For some labels the text is displayed on two lines, while the text fits exactly on one line in the form designer. If I do not define a Sub Main, but set the MainForm as Startup form, the form shows correctly. Has anyone an idea what could be the cause of this strange behaviour? Shared Sub main() Application.EnableVisualStyles() Application.DoEvents() Application.Run(MainForm) End Sub Thanks, Marc
Its the EnableVisualStyles line that may be causing it. This tell the app to use the systems theme styles render instead of the standard one. This changes stuff like font rendering. What version of Visual Studio are you using?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Its the EnableVisualStyles line that may be causing it. This tell the app to use the systems theme styles render instead of the standard one. This changes stuff like font rendering. What version of Visual Studio are you using?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...I'm using Visual Studio 2008 Professional Edition. Is there a way how I can make sure that the style renderer that is used on runtime is the same as the one used in the form designer?
-
I'm using Visual Studio 2008 Professional Edition. Is there a way how I can make sure that the style renderer that is used on runtime is the same as the one used in the form designer?
When Dave said EnableVisualStyles is what triggers the theme-based renderer, doesn't that suggest you to try and run your code without that statement, and see what gives? :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
-
When Dave said EnableVisualStyles is what triggers the theme-based renderer, doesn't that suggest you to try and run your code without that statement, and see what gives? :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
Ok, sorry, should have mentioned that I tried that already. But when I remove the EnableVisualStyles statement, the whole XP-style disappears (of course ;-) ). It seems to me that the EnableVisualStyles statement is correct, as I want to use the systems theme. The form is during run-time and in the form designer almost identical (i.e. using XP style), the only little difference is that the text on labels and buttons is moved about 1 or 2 pixels, which results in some cases in two lines of text in stead of one, as the text doesn't fit on one line anymore. Of course I could make the labels and buttons a few pixels larger. It's just that I don't like the fact that there is a differce between the form in the designer and in run-time. Someting must cause the difference... Furthermore, when I start the form by setting the MainForm as Startup form in the project properties, and enabling XP visual styles, the form shows correctly. So any help / suggenstions are welcome!
-
Ok, sorry, should have mentioned that I tried that already. But when I remove the EnableVisualStyles statement, the whole XP-style disappears (of course ;-) ). It seems to me that the EnableVisualStyles statement is correct, as I want to use the systems theme. The form is during run-time and in the form designer almost identical (i.e. using XP style), the only little difference is that the text on labels and buttons is moved about 1 or 2 pixels, which results in some cases in two lines of text in stead of one, as the text doesn't fit on one line anymore. Of course I could make the labels and buttons a few pixels larger. It's just that I don't like the fact that there is a differce between the form in the designer and in run-time. Someting must cause the difference... Furthermore, when I start the form by setting the MainForm as Startup form in the project properties, and enabling XP visual styles, the form shows correctly. So any help / suggenstions are welcome!
OK, I don't know the solution; I tend to make my controls slightly wider to avoid such issues. BTW: what will happen if you ever need to internationalize your Form? :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
-
OK, I don't know the solution; I tend to make my controls slightly wider to avoid such issues. BTW: what will happen if you ever need to internationalize your Form? :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
Ok, thanks anyway! Someone else any suggestions???
-
Ok, thanks anyway! Someone else any suggestions???
There is a relatively well known problem in this context, caused by the differences in the way that GDI and GDI+ do their rendering which may explain your problem. This[^] explains it and has a demo project. There is a better explanation that I cannot locate at the moment. Some time ago I posted it on CP for another member. At that time I found it by Googling gdi v gdi+, which is where I got the link above. If you have more patience than I, give it a try. :)
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Ok, thanks anyway! Someone else any suggestions???
Ok, I finally found the solution. If I set the buttons and labels 'FlatStyle' property to 'Sytem' in stead of 'Standard', the form shows up correctly in run-time. However, I'm still wondering why there is a difference between setting EnableVisualStyles in code (showing the text different then in the designer) and setting 'Enable XP Visual styles' in the project properties (showing the text the same as in the designer)...