I recently began learning Windows programming with VB and I'm having some issues with an assignment. The basis is to create a window called Drawing with two group boxes, one to change the color and one to change the size, and a panel where the drawing takes place. See image: http://postimg.org/image/xq7xddzj7/
My problem is that the drawing is taking place outside the panel and I'm not entirely sure why.
Public Class Form1
'Determines whether or not to paint
Private shouldPaint As Boolean = False
'Should paint when the mouse is pressed down
Private Sub drawPanel_MouseDown(sender As Object, e As MouseEventArgs)
Handles drawPanel.MouseDown
shouldPaint = True
End Sub
'Draw circles when the mouse is pressed and moving
Private Sub drawPanel_MouseMove(sender As Object, e As MouseEventArgs)
Handles drawPanel.MouseMove
If (shouldPaint) Then
' Draw a circle where the mouse pointer is present
Using g As Graphics = CreateGraphics()
g.FillEllipse(New SolidBrush(Color.BlueViolet), e.X, e.Y, 4, 4)
End Using
End If
End Sub
'Do not paint when the mouse is not pressed
Private Sub drawPanel_MouseUp(sender As Object, e As MouseEventArgs)
Handles drawPanel.MouseUp
shouldPaint = False
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
I have yet to start any coding for the color and size buttons since this currently isn't working inside the panel. Any guidance here would be greatly appreciated!
Don't know how VB works but can you debug your program step for step and see what the values are that you get. Most likely it retrieves the absolute value of your cursor or something similar. But as Disch said you should have posted this in a VB forum