0

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
1
Contributor
2
Replies
6
Views
5 Years
Discussion Span
Last Post by Frederick2
0

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
0

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
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.