Results 1 to 16 of 16

Thread: VB Resize Not working after Minimze

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    VB Resize Not working after Minimze

    When our app is running in Windowed mode, if a user minimizes and then restores the software it is not resizing properly. It is acting like the screen is Maximized the way it makes everything too large. What is the best way to fix this?

    I would like to make sure I am handling everything properly from the first time it loads, to Maximizeing, Minimizeing, Restores... I don't know why this is so hard, but I just can't get it right.
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: VB Resize Not working after Minimze

    It would all depend on how you are resizing it. Are you using code, or the built in features docking/anchoring that do all this for you?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: VB Resize Not working after Minimze

    I think the one I am having the most issues with is the one Microsoft is taking care of automatically, txtQuestion.width. Any idea why MS would be resizing it wrong?

    Here is what I am doing inside my Resize, but like I said before, it looks like the issue is not in here:
    vb Code:
    1. Public Sub frmStudy_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
    2.         On Error Resume Next
    3.  
    4.         txtQuestion.Height = (Me.Height - 725) / 2 + 208
    5.         txtAnswer.Height = txtQuestion.Height
    6.  
    7.         ufrMultiChoice.Height = txtQuestion.Height
    8.         ufrMultiChoice.Width = txtQuestion.Width
    9.         ufrMultiChoice.Top = txtQuestion.Top + txtQuestion.Height + 5
    10.         txtAnswer.Top = ufrMultiChoice.Top
    11.  
    12.         lblAnswer.Top = ufrMultiChoice.Top
    13.         btnPlayAnswers.Top = ufrMultiChoice.Top + lblAnswer.Height + 7
    14.  
    15.         resizeMultipleAnswers()
    16.     End Sub
    Last edited by rex64; Jun 28th, 2012 at 03:00 PM.
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: VB Resize Not working after Minimze

    So you are coding this yourself then. Give it up as a bad job and read this instead . An alternative if you dynamically add controls (which your code suggests it might), then you can use the layout controls.

    Note, possibly you are getting an Exception but you have the awful

    On Error Resume Next

    Line which is hiding it. This has been replaced with TryCatch, I would highly suggest replacing this!

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: VB Resize Not working after Minimze

    In the future you should consider overriding SetBoundsCore to control sizing since most things to do with resizing call that internal function.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: VB Resize Not working after Minimze

    In addition to removing the On Error Resume Next I would suggest that the entire code be contained within an If Then block which tests the windowstate. You should not be executing any resize code if the windowstate is minimized.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: VB Resize Not working after Minimze

    The windows state helped. I removed the On Error, but I am NOT getting any errors. However, when I go from Maximized to Normal, some of the objects are WAY to wide. Any ideas?
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: VB Resize Not working after Minimze

    I tried several things in here, but they are always too big.

    vb Code:
    1. Public Sub resizeMultipleAnswers() Handles rbOption1.TextChanged, rbOption2.TextChanged, rbOption3.TextChanged, rbOption4.TextChanged
    2.         rbOption1.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    3.         rbOption2.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    4.         rbOption3.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    5.         rbOption4.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    6.  
    7.         rbOption1.Size = rbOption1.MaximumSize
    8.         rbOption1.Size = rbOption2.MaximumSize
    9.         rbOption3.Size = rbOption3.MaximumSize
    10.         rbOption4.Size = rbOption4.MaximumSize
    11.  
    12.         Dim tempvar As Size = rbOption4.MaximumSize
    13.         Dim tempvar2 As Integer = Me.txtQuestion.Width
    14.         Dim tempvar3 As Integer = Me.Width
    15.  
    16.         rbOption1.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    17.         rbOption2.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    18.         rbOption3.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    19.         rbOption4.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    20.  
    21.  
    22.         rbOption2.Top = rbOption1.Top + rbOption1.Height + 6
    23.         rbOption3.Top = rbOption2.Top + rbOption2.Height + 6
    24.         rbOption4.Top = rbOption3.Top + rbOption3.Height + 6
    25.  
    26.  
    27.  
    28.         _lblNumber_0.Top = rbOption1.Top + rbOption1.Height / 2 - 11
    29.         _lblNumber_1.Top = rbOption2.Top + rbOption2.Height / 2 - 11
    30.         _lblNumber_2.Top = rbOption3.Top + rbOption3.Height / 2 - 11
    31.         _lblNumber_3.Top = rbOption4.Top + rbOption4.Height / 2 - 11
    32.  
    33.  
    34.  
    35.         fixRTL(rbOption1)
    36.         fixRTL(rbOption2)
    37.         fixRTL(rbOption3)
    38.         fixRTL(rbOption4)
    39.     End Sub
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: VB Resize Not working after Minimze

    Why are you defining all these vars and not using them?
    Why is this in the textchanged event?
    Code:
    Dim tempvar As Size = rbOption4.MaximumSize
    Dim tempvar2 As Integer = Me.txtQuestion.Width
    Dim tempvar3 As Integer = Me.Width

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: VB Resize Not working after Minimze

    The tempvars are just for debugging so I could compare the widths. Everything is as expected. Even the Widths that the radio buttons are set to appear correct, they just are way to long when actually displayed on the form.

    Quote Originally Posted by DataMiser View Post
    Why are you defining all these vars and not using them?
    Why is this in the textchanged event?
    Code:
    Dim tempvar As Size = rbOption4.MaximumSize
    Dim tempvar2 As Integer = Me.txtQuestion.Width
    Dim tempvar3 As Integer = Me.Width
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: VB Resize Not working after Minimze

    I still do not understand why you would have that in a handler for textchanged. Seems like that would execute far to often best case it will waste cpu cycles worst case cause unexpected behaviour

  12. #12
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,378

    Re: VB Resize Not working after Minimze

    I think that turning option strict/explicit on would work out a few errors, becuase this:
    Code:
    _lblNumber_0.Top = rbOption1.Top + rbOption1.Height / 2 - 11
    would def throw an error. Dividing the hieght by two would return a double, and an integer plus a double does not equal an integer. Take a look at grimfort's option strict/explicit link in the signature.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: VB Resize Not working after Minimze

    Ok, I turned on Option Explicit and Option Strict. The same thing is happening. If you resize the window it works amazing. But if you Maximize and then go to Normal it does not resize properly. Notice that the scroll bar shows that the control is super wide. But if you look here the sizes seem correct on the tempvars.

    tempvar = {Width = 777 Height = 0}
    tempvar2 = 845
    tempvar3 = 1020

    vb Code:
    1. Public Sub frmStudy_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
    2.  
    3.         'On Error Resume Next
    4.  
    5.         If WindowState <> FormWindowState.Minimized Then
    6.             txtQuestion.Height = CInt((Me.Height - 725) / 2 + 208)
    7.             txtAnswer.Height = txtQuestion.Height
    8.  
    9.             ufrMultiChoice.Height = txtQuestion.Height
    10.             ufrMultiChoice.Width = txtQuestion.Width
    11.             ufrMultiChoice.Top = txtQuestion.Top + txtQuestion.Height + 5
    12.             txtAnswer.Top = ufrMultiChoice.Top
    13.  
    14.             lblAnswer.Top = ufrMultiChoice.Top
    15.             btnPlayAnswers.Top = ufrMultiChoice.Top + lblAnswer.Height + 7
    16.  
    17.             resizeMultipleAnswers()
    18.         End If
    19.     End Sub
    20.  
    21.     Public Sub resizeMultipleAnswers() Handles rbOption1.TextChanged, rbOption2.TextChanged, rbOption3.TextChanged, rbOption4.TextChanged
    22.         rbOption1.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    23.         rbOption2.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    24.         rbOption3.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    25.         rbOption4.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    26.  
    27.         rbOption1.Size = rbOption1.MaximumSize
    28.         rbOption1.Size = rbOption2.MaximumSize
    29.         rbOption3.Size = rbOption3.MaximumSize
    30.         rbOption4.Size = rbOption4.MaximumSize
    31.  
    32.         Dim tempvar As Size = rbOption4.MaximumSize
    33.         Dim tempvar2 As Integer = Me.txtQuestion.Width
    34.         Dim tempvar3 As Integer = Me.Width
    35.  
    36.         rbOption1.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    37.         rbOption2.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    38.         rbOption3.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    39.         rbOption4.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
    40.  
    41.  
    42.         rbOption2.Top = rbOption1.Top + rbOption1.Height + 6
    43.         rbOption3.Top = rbOption2.Top + rbOption2.Height + 6
    44.         rbOption4.Top = rbOption3.Top + rbOption3.Height + 6
    45.  
    46.  
    47.  
    48.         _lblNumber_0.Top = CInt(rbOption1.Top + rbOption1.Height / 2 - 11)
    49.         _lblNumber_1.Top = CInt(rbOption2.Top + rbOption2.Height / 2 - 11)
    50.         _lblNumber_2.Top = CInt(rbOption3.Top + rbOption3.Height / 2 - 11)
    51.         _lblNumber_3.Top = CInt(rbOption4.Top + rbOption4.Height / 2 - 11)
    52.  
    53.  
    54.  
    55.         fixRTL(rbOption1)
    56.         fixRTL(rbOption2)
    57.         fixRTL(rbOption3)
    58.         fixRTL(rbOption4)
    59.     End Sub
    Attached Images Attached Images  
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  14. #14
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: VB Resize Not working after Minimze

    It is hard for us to debug something that could depend on so many other things, such as control parents, other event code (why are you changing the MaximumSize?) that could be changing the order.

    I mentioned above, but will mention again. Give up on hardcoding this, just anchor the controls, job done.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: VB Resize Not working after Minimze

    Each of the 4 controls re-size their height automatically to fit content, I did not think that anchors work with this? Basically the 4 controls are in a panel.

    Quote Originally Posted by Grimfort View Post
    It is hard for us to debug something that could depend on so many other things, such as control parents, other event code (why are you changing the MaximumSize?) that could be changing the order.

    I mentioned above, but will mention again. Give up on hardcoding this, just anchor the controls, job done.
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  16. #16
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: VB Resize Not working after Minimze

    You can anchor controls within controls. If you want to collect the answers together, put them into their own panel. A panel has an AutoScroll property, which will auto-add scroll bars when your view is outsize the area. You also have layout controls, one being a table, which can simply be 1 column X 4 rows. All you set is the height.

    You can also use splitter panels to allow the user to manually size the area, or, just use it with a fixedpanel (ie the question), and sit the answers within the other side of the splitter. It is just a case of breaking down the screen into sections, yours looks like it has 4 major (2x2 grid, perfect for tablelayout). The answers has more, so maybe another tablelayout inside (put it inside a panel first, makes selection easier).

    I have had issues with sizing when dynamically inserting usercontrols within tabbed controls, within usercontrols, within docked forms, within MDI. And then I reverted to a bit of code to fix it. Other than that, everything else is easy do-able by anchoring and docking.

Posting Permissions

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



Click Here to Expand Forum to Full Width