PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Why is my Form1 shrinking ?-VBForums
Results 1 to 16 of 16

Thread: [RESOLVED] Why is my Form1 shrinking ?

  1. #1

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Resolved [RESOLVED] Why is my Form1 shrinking ?

    What's going on here ?

    My Form1's design size is 800x600
    I have two Labels and some buttons sitting in a TableLayoutPanel.
    Label2 is only there to be measured.
    Code:
        Private Sub Button2_Click() Handles Button2.Click
            Label1.Text = Label2.Width.ToString & " W x "
            Label1.Text += Label2.Height.ToString & " H " & vbCrLf
            Label1.Text += Me.Width.ToString & " x "
            Label1.Text += Me.Height.ToString
        End Sub
    When I click Button2, Label1 says:
    68W x 51H
    602 x 488
    So Form1 is not 800x600 !
    Add into 'Form1_Load'
    Code:
            Me.Width = 800
            Me.Height = 600
    ...now when I click Button2, Label1 says:
    68W x 65H
    800 x 600
    Next conundrum:
    Label2 is only there to be measured. It's margins and padding are set to 'All = 0' and it's Dock is set to 'Fill', the TLP columns are set to 'Absolute 90 px' and the rows are set to '12%'.
    As you can see, when the form isn't 800x600 Label2's width is not 90 px. and neither is it when the form IS 800x600, but at least the width is 68 px for both form sizes.
    Code:
        Private Sub Button3_Click() Handles Button3.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    Click Button3, then Button2, and Label1 says:
    68W x 95H
    1552 x 850
    Again, the width is 68 px so something's working, just not as I expect.

    What's going on ? Can I do anything about it?


    Poppa.

    VS2015
    Windows10.
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2014
    Posts
    285

    Re: Why is my Form1 shrinking ?

    When you place a control inside a TableLayoutPanel, doesn't "me" refer to the actual panel and not the form? Ie the control is now a child of the panel, not the form?

    I can't remember the exact rules for that atm, but try changing "me" to "form1" (or whatever your form is called).

  3. #3
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by Nirwanda View Post
    When you place a control inside a TableLayoutPanel, doesn't "me" refer to the actual panel and not the form? Ie the control is now a child of the panel, not the form?

    I can't remember the exact rules for that atm, but try changing "me" to "form1" (or whatever your form is called).
    Me always refers to the type containing the code.

  4. #4
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Why is my Form1 shrinking ?

    Poppa,

    Have you inadvertently set the Form's AutoSize property to True and the AutoSizeMode to GrowAndShrink?

  5. #5

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by TnTinMN View Post
    Poppa,

    Have you inadvertently set the Form's AutoSize property to True and the AutoSizeMode to GrowAndShrink?
    Just checked (To be sure)
    AutoSize property IS set to False.
    AutoSizeMode IS set to Grow (only).

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  6. #6
    Lively Member darkbb's Avatar
    Join Date
    Jan 2016
    Posts
    91

    Lightbulb Re: Why is my Form1 shrinking ?

    Quote Originally Posted by Poppa Mintin View Post
    Just checked (To be sure)
    AutoSize property IS set to False.
    AutoSizeMode IS set to Grow (only).

    Poppa.
    hey... Poppa... Thats, a Cute name...!!

    i think its just the HIGH DPI settings of windows...

    1) Go and right-click the "WindowsApplication1.exe" file & Select Properties
    2) Select Compatibility Tab & check (Mark Tick) the "Disable display scaling on high DPI settings."

    and, then, try run it and see...

  7. #7

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by darkbb View Post
    hey... Poppa... Thats, a Cute name...!!

    i think its just the HIGH DPI settings of windows...

    1) Go and right-click the "WindowsApplication1.exe" file & Select Properties
    2) Select Compatibility Tab & check (Mark Tick) the "Disable display scaling on high DPI settings."

    and, then, try run it and see...
    Thanks Darkbb that's interesting...

    Under
    Project Properties > Application > [View Windows Settings ]
    I get a list headed: app.manifest

    I have no real idea what any of this page is telling me, but this section looks as though it may be relevant:

    [quote]
    </application>
    </compatibility>

    <!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
    DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
    to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
    also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
    <!--
    <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
    </application>
    -->
    [\quote]

    Does this mean that there is some command I can enter to ensure re-scaling doesn't occur ?

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  8. #8

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by darkbb View Post
    hey... Poppa... Thats, a Cute name...!!

    i think its just the HIGH DPI settings of windows...

    1) Go and right-click the "WindowsApplication1.exe" file & Select Properties
    2) Select Compatibility Tab & check (Mark Tick) the "Disable display scaling on high DPI settings."

    and, then, try run it and see...
    Thanks Darkbb that's interesting...

    Under
    Project Properties > Application > [View Windows Settings ]
    I get a list headed: app.manifest

    I have no real idea what any of this page is telling me, but this section looks as though it may be relevant:

    </application>
    </compatibility>

    <!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
    DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
    to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
    also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
    <!--
    <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
    </application>
    -->
    Does this mean that there is some command I can enter to ensure re-scaling doesn't occur ?

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  9. #9
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347

    Re: Why is my Form1 shrinking ?

    You said you have a TableLayoutPanel ... I am guessing Label2 is in some cell in that... cells can scale by percent ...
    What is the layout for the tlp and what cell is Label2 in?

    As for the initial size being different I would think DPI is coming into play...

    Microsoft are really behind the 8 ball here, Windows manages DPI absolutely horridly.
    You should always develop in 72 DPI for winforms thanks to M$ completely botching this up... they should have made their scaling native with the OS (like apple (the one good thing about them imho )) rather than "emulating" it... but enough rant.

    Kris

  10. #10
    Lively Member darkbb's Avatar
    Join Date
    Jan 2016
    Posts
    91

    Lightbulb Re: Why is my Form1 shrinking ?

    Quote Originally Posted by Poppa Mintin View Post
    Thanks Darkbb that's interesting...

    Does this mean that there is some command I can enter to ensure re-scaling doesn't occur ?
    Poppa.
    Yep... U guessed it right...!! there could be some command...

    If u really want to ensure re-scaling doesn't occur follow these steps :

    1) Go the Forms designer (Form1.vb [Design]), then select your Form (by clicking at its title bar)

    2) Change AutoScaleMode property from Font (default) to Dpi.

    3) Go to Solution Explorer & Select "Show All Files"

    4) Inside Solution Explorer, Open My Project->Application.myapp->Application.Designer.vb

    5) Place the following code inside of Public Sub New() below MyBase.New(Global.Microsoft..... codeline.
    Vb.net Code:
    1. If (Environment.OSVersion.Version.Major >= 6) Then
    2.  SetProcessDPIAware()
    3. End If
    6) Paste the following code After End Sub of Public Sub New()
    Vb.net Code:
    1. <System.Runtime.InteropServices.DllImport("user32.dll")>
    2. Private Shared Function SetProcessDPIAware() As Boolean
    3. End Function

    I'm hope it works for U...


    Reference in this link
    Last edited by darkbb; Dec 14th, 2016 at 12:27 PM. Reason: *Sorry, missed the reference link

  11. #11

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by darkbb View Post
    Yep... U guessed it right...!! there could be some command...

    If u really want to ensure re-scaling doesn't occur follow these steps :

    1) Go the Forms designer (Form1.vb [Design]), then select your Form (by clicking at its title bar)

    2) Change AutoScaleMode property from Font (default) to Dpi.

    3) Go to Solution Explorer & Select "Show All Files"

    4) Inside Solution Explorer, Open My Project->Application.myapp->Application.Designer.vb

    5) Place the following code inside of Public Sub New() below MyBase.New(Global.Microsoft..... codeline.
    Vb.net Code:
    1. If (Environment.OSVersion.Version.Major >= 6) Then
    2.  SetProcessDPIAware()
    3. End If
    6) Paste the following code After End Sub of Public Sub New()
    Vb.net Code:
    1. <System.Runtime.InteropServices.DllImport("user32.dll")>
    2. Private Shared Function SetProcessDPIAware() As Boolean
    3. End Function

    I'm hope it works for U...
    Thank you again Darkbb, that's done the trick.

    Brilliant, this problem's been bugging me for a long while... Now I have the fix.


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  12. #12
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by Poppa Mintin View Post
    ...Does this mean that there is some command I can enter to ensure re-scaling doesn't occur ?
    There is no need for you to issue any command to declare your application as DPI Aware. All you need to do is un-comment that that section of the app.manifest.

    I.E. change:
    Code:
      <!--
      <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
        </windowsSettings>
      </application>
      -->
    to:
    Code:
      <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
        </windowsSettings>
      </application>

  13. #13

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by TnTinMN View Post
    There is no need for you to issue any command to declare your application as DPI Aware. All you need to do is un-comment that that section of the app.manifest.
    Thank you TnTinMN,

    Sadly I have absolutely no idea what language app.manifest is written in and would be most unhappy messing with it.

    However, on the bright side, item 2 of Darkbb's post: 2) Change AutoScaleMode property from Font (default) to DPI.
    Seems to be all I need to do for the moment... It certainly solves (appears to solve) my problem.


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  14. #14
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by Poppa Mintin View Post
    Thank you TnTinMN,

    Sadly I have absolutely no idea what language app.manifest is written in and would be most unhappy messing with it.
    The file is in XML format. A pretty standard format that is widely used in .Net.

    If making a simple one time change to a text file makes you unhappy, while you have no problem editing a designer generated file that can be overwritten by the designer (i.e. your edits will be lost) if you make changes to the application configuration such as changing the startup form, I don't know what to say except: "To each their own."

    I foresee a future question: Why are my changes to "Application.Designer.vb" disappearing?

  15. #15

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,812

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by tntinmn View Post
    i foresee a future question: Why are my changes to "application.designer.vb" disappearing?
    lol...
    Along with the sunshine there has to be a little rain sometime.

  16. #16
    Lively Member darkbb's Avatar
    Join Date
    Jan 2016
    Posts
    91

    Re: Why is my Form1 shrinking ?

    Quote Originally Posted by Poppa Mintin View Post
    Thank you again Darkbb, that's done the trick.
    Brilliant, this problem's been bugging me for a long while... Now I have the fix.
    Poppa.
    Hi Poppa.... Welcome...

    U forgot to rate the post...!! Please do...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width