Free hand drowing

LoNeLy

New member
Joined
May 14, 2009
Messages
1
Programming Experience
3-5
Good morning/ afternoon to all of you ..:)

it's the first time for me to be here ..!!
my english may seems bad hhhhhh :(
but anyway , i like programming and i'm studying some programming language ..
i'm trying to do taskes in VB.Net but i faced difficulty..:eek:
if u can help me i'll appraciate ur help ..:rolleyes:

This is the question

Write a program that allows the user to draw 'free-hand' images with the mouse in a PictureBox. Be sure to provide the following:
1. A Button to allow users to clear the image in the PictureBox
2. A ListBox to allow users to change the colour of the pen. Provide few options for colour.
3. A way (radio or list) to set the drawing width. Provide few options for the width.
4. A button to exit
Be sure that when the user makes a selection from the menu, the appropriate control is updated to reflect the user's choice of colour and width.
Important Note: You will need to use some of the mouse events. In particular the mouse move event should contain your drawing rather than the paint event of the picture box. This has the effect of you minimize the drawing would be gone which is ok for this small assignment.


i'll post what i have write


VB.NET:
Public Class Form1

    Dim image1 As Bitmap

    Dim gr As Graphics

    Dim Pen1 As New Pen(Color.Black, 5)

    Private Sub picturebox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

        gr = PictureBox1.CreateGraphics 'Paints the graphic to the form

    End Sub



    Private Sub picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove


        gr.DrawLine(Pen1, e.X, e.Y, e.X + 3, e.Y + 3)

    End Sub


    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

    End Sub

    Private Sub lstColour_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstColour.SelectedIndexChanged

        If Me.lstColour.SelectedIndex = 0 Then
            Pen1.Color = Color.Blue
        ElseIf lstColour.SelectedIndex = 1 Then
            Pen1.Color = Color.Red
        ElseIf lstColour.SelectedIndex = 2 Then
            Pen1.Color = Color.Green
        End If

    End Sub

    Private Sub lstWidth_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstWidth.SelectedIndexChanged

    End Sub
End Class

but whenever i run the form it gives me an error on that part
VB.NET:
gr.DrawLine(Pen1, e.X, e.Y, e.X + 3, e.Y + 3)

and i don't know how to clear the picbox after drowing and how to change the size of drowing..!!

i know i'm asking alot:p but i want to learn ;)

Thanks in advance:)
 
The first thing to note is that it doesn't help us much to know that you get an error without knowing the error message.

The next thing to note is that you're going about this in the wrong way. First up, you must do ALL your drawing in the Paint event handler.

Second, you don't create a Graphics object because the Paint event handler already provides you one in e.Graphics.

Thirdly, you don't have to erase anything because all your drawing gets erased every time the control is repainted. That's why you have to draw on every Paint event: if you don't your drawing will be lost the next time the control is painted. You need to store the data that describes your drawing in member variables and then use those variables to draw in the Paint event handler. Any time you want to change the drawing, i.e. add, remove or change anything, you simply update your data and then force a repaint, which you do by calling Refresh or, preferably, Invalidate and Update.

You might want to take a look at [ame="http://www.vbforums.com/showthread.php?t=426684"]this[/ame].
 

Latest posts

Back
Top