justlearning
Member
- Joined
- Dec 11, 2008
- Messages
- 16
- Programming Experience
- Beginner
Write a program that allows the user to draw 'free-hand' images with the mouse in a PictureBox. Be sure to provide the following:
A Button to allow users to clear the image in the PictureBox
A ComboBox to allow users to change the color of the pen
A set of radio buttons to set the drawing width
A menu containing at least the following items:
Clear
Change Color (then provide the colors that are in your ComboBox)
Change width (then provide the sizes in your RadioButtons)
Be sure that when the user makes a selection from the menu, the appropriate control (Button, ComboBox or RadioButton) is updated to reflect the user's choice
I have gotten to the point where the user is able to draw in my picture box but I cannot figure out how to change the color or size of the brush. Right now, you can see below, I have both the color and the size set to a specific color and size. Unfortunately I do not know how to take this out and put in a string that reads the combobox colors and the radiobuttons selection. I would like to set the default color to black and the default size to 10, 10. If you can help please let me know. Thanks so much.
VB.NET:
Public Class Form1
'Set shouldpaint to true/false to use for mousedown/mouseup
Dim shouldpaint As Boolean = False
'Form load section
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ColorBox.SelectedItem(0) = Color.Aqua
ColorBox.SelectedItem(1) = Color.Blue
ColorBox.SelectedItem(2) = Color.Red
End Sub
Private Sub Drawpb_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Drawpb.MouseDown
'Set drawpd to draw when mouse was held down
shouldpaint = True
End Sub
Private Sub Drawpb_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Drawpb.MouseUp
'Set drawpd not to draw when mouse was up
shouldpaint = False
End Sub
Private Sub Drawpb_mousemove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Drawpb.MouseMove
If shouldpaint Then
'Declare g for graphics
Dim g As System.Drawing.Graphics
'set drawpad as site for freehand drawing
g = Drawpb.CreateGraphics()
'Set brush color as black and size of brush to 20, 20
g.FillEllipse( _
New SolidBrush(Color.Black), e.X, e.Y, 20, 20)
End If
End Sub
'Exit Button
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'End program
Me.Close()
End
End Sub
'Clear Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Clear Drawpad
Drawpb.Refresh()
End Sub
'Menu strip: Close
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
'End Program
Me.Close()
End
End Sub
'Menu Strip: Clear
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
'Clear Drawpad
Drawpb.Refresh()
End Sub
'Color ComboBox
Private Sub ColorBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorBox.SelectedIndexChanged
End Sub
End Class
I also included a screen shot of my gui.
Please let me know if you can help me. Thanks again.