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.
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?
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:
Public Sub frmStudy_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
On Error Resume Next
txtQuestion.Height = (Me.Height - 725) / 2 + 208
txtAnswer.Height = txtQuestion.Height
ufrMultiChoice.Height = txtQuestion.Height
ufrMultiChoice.Width = txtQuestion.Width
ufrMultiChoice.Top = txtQuestion.Top + txtQuestion.Height + 5
txtAnswer.Top = ufrMultiChoice.Top
lblAnswer.Top = ufrMultiChoice.Top
btnPlayAnswers.Top = ufrMultiChoice.Top + lblAnswer.Height + 7
resizeMultipleAnswers()
End Sub
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!
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.
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.
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?
Re: VB Resize Not working after Minimze
I tried several things in here, but they are always too big.
vb Code:
Public Sub resizeMultipleAnswers() Handles rbOption1.TextChanged, rbOption2.TextChanged, rbOption3.TextChanged, rbOption4.TextChanged
rbOption1.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption2.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption3.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption4.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption1.Size = rbOption1.MaximumSize
rbOption1.Size = rbOption2.MaximumSize
rbOption3.Size = rbOption3.MaximumSize
rbOption4.Size = rbOption4.MaximumSize
Dim tempvar As Size = rbOption4.MaximumSize
Dim tempvar2 As Integer = Me.txtQuestion.Width
Dim tempvar3 As Integer = Me.Width
rbOption1.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption2.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption3.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption4.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption2.Top = rbOption1.Top + rbOption1.Height + 6
rbOption3.Top = rbOption2.Top + rbOption2.Height + 6
rbOption4.Top = rbOption3.Top + rbOption3.Height + 6
_lblNumber_0.Top = rbOption1.Top + rbOption1.Height / 2 - 11
_lblNumber_1.Top = rbOption2.Top + rbOption2.Height / 2 - 11
_lblNumber_2.Top = rbOption3.Top + rbOption3.Height / 2 - 11
_lblNumber_3.Top = rbOption4.Top + rbOption4.Height / 2 - 11
fixRTL(rbOption1)
fixRTL(rbOption2)
fixRTL(rbOption3)
fixRTL(rbOption4)
End Sub
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
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
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
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
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.
1 Attachment(s)
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:
Public Sub frmStudy_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
'On Error Resume Next
If WindowState <> FormWindowState.Minimized Then
txtQuestion.Height = CInt((Me.Height - 725) / 2 + 208)
txtAnswer.Height = txtQuestion.Height
ufrMultiChoice.Height = txtQuestion.Height
ufrMultiChoice.Width = txtQuestion.Width
ufrMultiChoice.Top = txtQuestion.Top + txtQuestion.Height + 5
txtAnswer.Top = ufrMultiChoice.Top
lblAnswer.Top = ufrMultiChoice.Top
btnPlayAnswers.Top = ufrMultiChoice.Top + lblAnswer.Height + 7
resizeMultipleAnswers()
End If
End Sub
Public Sub resizeMultipleAnswers() Handles rbOption1.TextChanged, rbOption2.TextChanged, rbOption3.TextChanged, rbOption4.TextChanged
rbOption1.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption2.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption3.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption4.MaximumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption1.Size = rbOption1.MaximumSize
rbOption1.Size = rbOption2.MaximumSize
rbOption3.Size = rbOption3.MaximumSize
rbOption4.Size = rbOption4.MaximumSize
Dim tempvar As Size = rbOption4.MaximumSize
Dim tempvar2 As Integer = Me.txtQuestion.Width
Dim tempvar3 As Integer = Me.Width
rbOption1.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption2.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption3.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption4.MinimumSize = New System.Drawing.Size(ufrMultiChoice.Width - 68, 0)
rbOption2.Top = rbOption1.Top + rbOption1.Height + 6
rbOption3.Top = rbOption2.Top + rbOption2.Height + 6
rbOption4.Top = rbOption3.Top + rbOption3.Height + 6
_lblNumber_0.Top = CInt(rbOption1.Top + rbOption1.Height / 2 - 11)
_lblNumber_1.Top = CInt(rbOption2.Top + rbOption2.Height / 2 - 11)
_lblNumber_2.Top = CInt(rbOption3.Top + rbOption3.Height / 2 - 11)
_lblNumber_3.Top = CInt(rbOption4.Top + rbOption4.Height / 2 - 11)
fixRTL(rbOption1)
fixRTL(rbOption2)
fixRTL(rbOption3)
fixRTL(rbOption4)
End Sub
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.
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
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.
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.