I receive the error message: Object reference not set to an instance of an object, to the following code:
Do I need to Dim something as New? If so, how may I go about resolving this problem?
VB.NET:
Sub createTextIcon()
Dim myColor As Color
If TextNewText2.Text = "Red" Then
myColor = _
Color.Red
End If
If TextNewText2.Text = "Green" Then
myColor = _
Color.Green
End If
If TextNewText2.Text = "Blue" Then
myColor = _
Color.Blue
End If
If TextNewText2.Text = "Purple" Then
myColor = _
Color.Purple
End If
If TextNewText2.Text = "Yellow" Then
myColor = _
Color.Yellow
End If
If TextNewText2.Text = "Orange" Then
myColor = _
Color.Orange
End If
If TextNewText2.Text = "White" Then
myColor = _
Color.White
End If
If TextNewText2.Text = "Black" Then
myColor = _
Color.Black
End If
Dim fontToUse As Font = New Font("Microsoft Sans Serif", 14, FontStyle.Regular, _
GraphicsUnit.Pixel)
Dim brushToUse As Brush = New SolidBrush(myColor)
Dim bitmapText As Bitmap = New Bitmap(20, 16)
Dim g As Graphics = Drawing.Graphics.FromImage(bitmapText)
Dim hIcon As IntPtr
Try
g.Clear(Color.Transparent)
g.DrawString(Label1.Text & "°", fontToUse, brushToUse, -3, -1)
hIcon = (bitmapText.GetHicon)
notifyText.Icon = Drawing.Icon.FromHandle(hIcon)
notifyText.Text = Label6.Text
Catch exc As Exception
MessageBox.Show(exc.InnerException.ToString, "Failure!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Do I need to Dim something as New? If so, how may I go about resolving this problem?