Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Form layout at runtime differs from design

Form layout at runtime differs from design

Scheduled Pinned Locked Moved Windows Forms
designquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 3327102
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • U User 3327102

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

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

      U 1 Reply Last reply
      0
      • D Dave Kreskowiak

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

        U Offline
        U Offline
        User 3327102
        wrote on last edited by
        #3

        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?

        L 1 Reply Last reply
        0
        • U User 3327102

          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?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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.


          U 1 Reply Last reply
          0
          • L Luc Pattyn

            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.


            U Offline
            U Offline
            User 3327102
            wrote on last edited by
            #5

            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!

            L 1 Reply Last reply
            0
            • U User 3327102

              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!

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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.


              U 1 Reply Last reply
              0
              • L Luc Pattyn

                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.


                U Offline
                U Offline
                User 3327102
                wrote on last edited by
                #7

                Ok, thanks anyway! Someone else any suggestions???

                H U 2 Replies Last reply
                0
                • U User 3327102

                  Ok, thanks anyway! Someone else any suggestions???

                  H Offline
                  H Offline
                  Henry Minute
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • U User 3327102

                    Ok, thanks anyway! Someone else any suggestions???

                    U Offline
                    U Offline
                    User 3327102
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups