I'm new at this.

How come this doesn't work...

Private Sub ColorKeyForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        'Draws diagonal line of dot and dash on form
        Dim objGraphics As Graphics = Me.CreateGraphics
        Dim objPen As Pen
        objPen = New Pen(Drawing.Color.DarkBlue, 3)
        objPen.DashStyle = Drawing2D.DashStyle.DashDot
        objGraphics.DrawLine(objPen, 20, 20, 400, 400)

  
        'Next routine does nothing
        Dim objPicGraphics As Graphics = picColorKey.CreateGraphics
        objPen = New Pen(Drawing.Color.Chartreuse, 5)
        objPen.DashStyle = Drawing2D.DashStyle.Dot
        objPicGraphics.DrawLine(objPen, 20, 20, 400, 400)

    End Sub

... the top part draws a line on the form but the second part does nothing. The picColorKey is a picture box on the form.

Handle paint event of picColorKey,

Private Sub picColorKey_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim objPen As Pen
        Dim objPicGraphics As Graphics = e.Graphics

        objPen = New Pen(Drawing.Color.Red, 5)
        objPen.DashStyle = Drawing2D.DashStyle.Solid
        objPicGraphics.DrawLine(objPen, 20, 20, 400, 400)
    End Sub

Thanks, that worked!

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.