Groups | Blog | Home
all groups > vb.net controls > january 2007 >

vb.net controls : Error message


Question NO[at]SPAM aol.com
1/2/2007 6:32:34 AM
I have the follwoing code That I copy from the Internet

Function GetRoot(ByVal C As Object, ByRef oX As Integer, ByRef oY As
Integer) As Control
Try
If Not IsNothing(C.BackgroundImage) Then Return C
If C.BackColor.ToString = Color.Transparent.ToString Then
oX += C.Left
oY += C.Top
Try
Select Case C.borderstyle
Case BorderStyle.FixedSingle
oX += 1
oY += 1
Case BorderStyle.Fixed3D
oX += 2
oY += 2

End Select
Catch

End Try

C = GetRoot(C.Parent, oX, oY)
End If
Catch ex As Exception
End Try
Return C
End Function

I keep getting the gollowing warning on the line

Select Case C.borderstyle

Operands of type Object used in expressions for 'Select', 'Case'
statements; runtime errors could occur.

How come
Jay B. Harlow [MVP - Outlook]
1/2/2007 7:21:41 AM
Question,
[quoted text, click to view]
The operand could be *any* object including an object that does not support
a BorderStyle property, consider using the actual type of parameter
expected, in this case Control.

It appears that you are attempting to calculate the border width of
controls. Rather then hard code the information I would suggest you use
SystemInformation instead:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.systeminformation.aspx


Something like:

[quoted text, click to view]
oX += SystemInformation.Border3DSize.X
oY += SystemInformation.Border3DSize.Y
[quoted text, click to view]
oX += SystemInformation.BorderSize.X
oY += SystemInformation.BorderSize.Y
[quoted text, click to view]

I would actually consider passing a single Point or Size parameter rather
then X & Y parameters

[quoted text, click to view]

or

[quoted text, click to view]

Depending on what the expected usage of the X & Y return values are.

Also using .NET 2.0 (VS 2005) you can use operator overloading on the Point
& Size variables:

position += SystemInformation.Border3DSize

size += SystemInformation.Border3DSize

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


[quoted text, click to view]
AddThis Social Bookmark Button