visualbasic assignment how to draw a multicolored worm! pliz help

You have to show some effort first. What have you got so far?

so far I have done this and this draws a straight line from the top left corner to the bottom right corner. I have tried adding other codes to make a worm like shape but I failed.

Public class form1
Dim MyGraphics as Graphics

Private Sub Button1_click(ByVal sender As system.Object_ByVal As system.EventArgs) Handles Button1.click

       MyGraphics=Me.CreateGraphics


   MyGraphics.Drawline(Pens.Black,0,0,500,500)

   End Sub
   End Class

There is also a DrawLines method.

I am trying to draw something that looks like a worm. the worm is supposed to have segments with different colors. any clues?

MyGraphics.Drawline(Pens.Black,0,0,50,50)
MyGraphics.Drawline(Pens.Red,50,50,75,75)
Pen myPen = new Pen(Color.Green, 5f)
MyGraphics.Drawline(myPen,75,75,150,100)
myPen.Width = 7f
myPen.Color = Color.LightSteelBlue
MyGraphics.Drawline(myPen,150,100,200,375)
etc. etc.

thank u sir that helped a bit! I still got a long way to go and a little more help would be great

What kind of help do you have in mind? I cannot guess that you know.

I am supposed to draw multicolored worms using graphics. I have tried adding the codes you provided but when I run it, it does not display anything. is there anything else I should try?

Instead of using the click event of a button, use the Paint event of the form. It will give you a PaintEventArgs argument which contains a Graphics object to draw in.Use the code already provided. It should work. Success!

Well, just try this:

Public Class Form1
    Dim MyGraphics As Graphics

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        MyGraphics = e.Graphics
        MyGraphics.DrawLine(Pens.Black, 0, 0, 50, 50)
        MyGraphics.DrawLine(Pens.Green, 50, 50, 75, 75)
        Dim myPen As New Pen(Color.Red, 5.0F)
        MyGraphics.DrawLine(myPen, 75, 75, 150, 100)
        myPen.Width = 7.0F
        myPen.Color = Color.LightSteelBlue
        MyGraphics.DrawLine(myPen, 150, 100, 200, 375)
    End Sub

End Class

yes there is success! it managed to draw three different colored lines! know I have a clue on what to do next, thank you sir for your help, it has been truly helpful

If you have any more questions, please do ask us, and mark this thread as solved.
Glad to help you out. :o)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.