E
eBob.com
I suppose this has to be my own dumb mistake, but it sure has me mystified.
If I step through the code below using the Debugger and Watch I see one
value, but the code reports, via MsgBox, a different value!
Private Function DeterminePanelUsableWidth(ByRef width As Integer) As
Integer
' determine the width of a panel with a vertical scroll bar
Dim somepanel As New Panel
somepanel.Height = 100
somepanel.AutoScroll = True
somepanel.Width = width
Dim whatever As New TextBox
whatever.Height = somepanel.Height * 2
whatever.Location = New Point(0, 0)
somepanel.Controls.Add(whatever)
Dim ii As Integer = 0
Dim whatever2 As New TextBox
whatever2.Height = somepanel.Height * 2
whatever2.Location = New Point(0, somepanel.Height * 2)
somepanel.Controls.Add(whatever2)
DeterminePanelUsableWidth = somepanel.ClientSize.Width
MsgBox("somepanel.ClientSize.Width is " &
somepanel.ClientSize.Width.ToString & vbCrLf & _
"DeterminePanelUsableWidth is " &
DeterminePanelUsableWidth.ToString)
End Function
For "somepanel.ClientSize.Width" the code sees a value of 479 (as reported
via the MsgBox), but using the Debugger and Watch I see a value of 459 -
which I'm reasonably sure is the right value. 479, incidentally, is the
value of "width" on entry to the DeterminePanelUsableWidth.
(What the function is trying to do is to figure out the usable width in a
panel, i.e. the width of the panel minus the width of the vertical scroll
bar. I know that it's an inelegant implementation of an inelegant
solution.)
Thanks, Bob
If I step through the code below using the Debugger and Watch I see one
value, but the code reports, via MsgBox, a different value!
Private Function DeterminePanelUsableWidth(ByRef width As Integer) As
Integer
' determine the width of a panel with a vertical scroll bar
Dim somepanel As New Panel
somepanel.Height = 100
somepanel.AutoScroll = True
somepanel.Width = width
Dim whatever As New TextBox
whatever.Height = somepanel.Height * 2
whatever.Location = New Point(0, 0)
somepanel.Controls.Add(whatever)
Dim ii As Integer = 0
Dim whatever2 As New TextBox
whatever2.Height = somepanel.Height * 2
whatever2.Location = New Point(0, somepanel.Height * 2)
somepanel.Controls.Add(whatever2)
DeterminePanelUsableWidth = somepanel.ClientSize.Width
MsgBox("somepanel.ClientSize.Width is " &
somepanel.ClientSize.Width.ToString & vbCrLf & _
"DeterminePanelUsableWidth is " &
DeterminePanelUsableWidth.ToString)
End Function
For "somepanel.ClientSize.Width" the code sees a value of 479 (as reported
via the MsgBox), but using the Debugger and Watch I see a value of 459 -
which I'm reasonably sure is the right value. 479, incidentally, is the
value of "width" on entry to the DeterminePanelUsableWidth.
(What the function is trying to do is to figure out the usable width in a
panel, i.e. the width of the panel minus the width of the vertical scroll
bar. I know that it's an inelegant implementation of an inelegant
solution.)
Thanks, Bob