About setting default Object properties to IColor
The following is an example VB .NET error:
- Error 1 Value of type 'System.Drawing.Color' cannot be converted to 'Integer'.
The following is the cause of the VB .NET error:
- In VB6, objects had a default property that could be used as a shortcut in the code. For example, the default property of a TextBox control was the Text property. You could type TextBox1 = "Hello" instead of TextBox1.Text = "Hello." In VB .NET, default properties are no longer supported. All property references must be fully qualified. During the upgrade, default properties for early-bound objects are resolved to the property name; however, late-bound objects cannot be resolved because it is impossible to determine a default property without knowing what the object is. Sometimes the VB6 to VB .NET upgrade wizard overly complicates the code. Evaluate the argument and correct the code.
The following shows the original VB6 code example:
Private Sub ChangeTextboxColor(aTextbox As TextBox, colNew As IColor) aTextbox.BackColor = colNew.RGB End Sub
The following shows the initial auto-translated code example:
[VB.NET]
'Initial auto-translated VB.NET conversion.
Private Sub ChangeTextboxColor(ByRef aTextBox As TextBox, ByVal colNew As ESRI.ArcGIS.Display.IColor)
aTextBox.BackColor = System.Drawing.ColorTranslator.FromOle(CInt(System.Drawing.ColorTranslator.FromOle(System.Convert.ToInt32(colNew.RGB))))
End Sub
The following shows the correct VB .NET translation code example:
[VB.NET]
'Correct VB .NET translation.
Private Sub ChangeTextboxColor(ByRef aTextBox As TextBox, ByVal colNew As ESRI.ArcGIS.Display.IColor)
aTextBox.BackColor = System.Drawing.ColorTranslator.FromOle(colNew.RGB)
End Sub
See Also:
Migrating from VB6 to VB.NETGeneral steps for migrating from VB6 to VB.NET
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |