How can I cause the Paint event to fire from a Form_Click() event? This is what I'm trying to do...

Public Class StrTests01
    Private Sub StrTests01_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim ps As Graphics = Me.CreateGraphics()
        'RaiseEvent StrTests01_Paint(sender, ps)
    End Sub
    Private Sub StrTests01_Paint(ByVal sender As Object, ByVal pea As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        pea.Graphics.DrawString("Hello, World!", Me.Font, New SolidBrush(SystemColors.WindowText), 0, 0)
    End Sub
End Class

I'm still struggling. Can't anyone help with this simple question? Here's what I have so far, but nothing's working...

Public Class StrTests01
    Private Sub StrTests01_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim ps As Graphics = Me.CreateGraphics()
        'RaiseEvent StrTests01_Paint(sender, ps)
        'RaiseEvent OnPaint(sender, ps)
        StrTests01_Paint(sender, ps)
    End Sub
    Private Sub StrTests01_Paint(ByVal sender As Object, ByVal pea As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        pea.Graphics.DrawString("Hello, World!", Me.Font, New SolidBrush(SystemColors.WindowText), 0, 0)
    End Sub
End Class

No need to reply. I just figured it out!

Public Class StrTests01
    Dim s1 As New String("")
    Private Sub StrTests01_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        s1 = "Here Is A String I Want To Draw!"
        Me.Invalidate()
    End Sub
    Private Sub StrTests01_Paint(ByVal sender As Object, ByVal pea As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        If s1.Length = 0 Then
            pea.Graphics.DrawString("Hello, World!", Me.Font, New SolidBrush(SystemColors.WindowText), 0, 0)
        Else
            pea.Graphics.DrawString(s1, Me.Font, New SolidBrush(SystemColors.WindowText), 0, 0)
        End If
    End Sub
End Class
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.