Drawing a line from a seperate class

bish

Member
Joined
Dec 30, 2008
Messages
14
Programming Experience
Beginner
The code below draws a simple line, this is currently in 'Form1_Paint'

I would like to be able to add this to a seperate class and build on it and then call it when needed, how do l do this?

VB.NET:
Expand Collapse Copy
        Dim blackPen As New Pen(Color.Black, 3)
        ' Draw line to screen.
        e.Graphics.DrawLine(blackPen, 5, 20, 5, 100)
 
I assume this relates to your other thread Bish.

From Form1_Paint, send e.graphics by reference to the other class, calling a method. For example,

VB.NET:
Expand Collapse Copy
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    AllDrawnShapes.DrawPrettyPictures(e.Graphics)
End Sub

and in the class AllDrawnShapes :-

VB.NET:
Expand Collapse Copy
Public Sub DrawPrettyPictures(ByRef eg As Graphics)
    With eg
        .DrawLine(Pens.Black, 0, 0, 100, 100)
        'and whatever else you want to draw here
    End With
End Sub
 
Yes it did thanks, i think ive got all my questions answered now and l can move forward, the rest should be easy, i emphasise SHOULD!!

Many Thanks

Bish
 
Back
Top