3
Contributors
12
Replies
54
Views
4 Years
Discussion Span
Last Post by ddanbe
0

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
0

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

0

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.

0

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

0

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?

0

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!

0

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
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.