Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27429

VB 2008 vb.net 3.5 variable not assigned

$
0
0
Hi,

I'm a VB.net beginner (Willis/Newsome Beginning Visual Basic 2008) working through this Wrox paint program, now i have a problem with these errors which I don't know why they have arisen:

Warning 1 Variable 'objGraphicsItem' is used before it has been assigned a value. A null reference exception could result at runtime. (PaintCanvas)
Error 2 Event 'LeftClick' cannot be found. (Wrox Paint)

Any clues as to what is going on? I'm running visual studio 2008 vb.net 3.5

I've listed the 2 classes below.



Public Class PaintCanvas
'Public enumerations
Public Enum GraphicTools As Integer
CirclePen = 0
End Enum
Public Enum GraphicSizes As Integer
Small = 4
Medium = 10
Large = 20
End Enum
'Public members
Public GraphicsItems As New ArrayList()
Public GraphicTool As GraphicTools = GraphicTools.CirclePen
Public GraphicSize As GraphicSizes = GraphicSizes.Medium
Public GraphicColor As Color = Color.Black

Private Sub DoMousePaint(ByVal e As MouseEventArgs)
'Store the new item somewhere
Dim objGraphicsItem As GraphicsItem
'What tool are you using?
Select Case GraphicTool
'CirclePen
Case GraphicTools.CirclePen

'Create a new graphics circle
Dim objGraphicsCircle As New GraphicsCircle()
'Set the point for drawing
objGraphicsCircle.SetPoint(e.X, e.Y, GraphicSize, _
GraphicColor, True)
'Store this for addition
objGraphicsItem = objGraphicsCircle
End Select
'Were you given an item?
If objGraphicsItem IsNot Nothing Then
'Add it to the list
GraphicsItems.Add(objGraphicsItem)
'Invalidate the control
Me.Invalidate(objGraphicsItem.Rectangle)
End If
End Sub

Private Sub PaintCanvas_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
'Is the left mouse button down?
If e.Button = MouseButtons.Left Then
DoMousePaint(e)
End If
End Sub

Private Sub PaintCanvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
'Is the left mouse button down?
If e.Button = MouseButtons.Left Then
DoMousePaint(e)
End If
End Sub

Private Sub PaintCanvas_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'Go through the list
For Each objGraphicsItem As GraphicsItem In GraphicsItems
'Do we need to be drawn?
If e.ClipRectangle.IntersectsWith(objGraphicsItem.Rectangle) Then
'Ask each item to draw itself
objGraphicsItem.Draw(e.Graphics)
End If
Next
End Sub
End Class

------------
Public Class Canvas

Private Sub PaintCanvas1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PaintCanvas1.Load

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub paletteColor_LeftClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles paletteColor.LeftClick

End Sub
End Class

Viewing all articles
Browse latest Browse all 27429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>