How can I make text flash using Graphics.DrawString

Is there a way to make the text in the following code flash on/off every 750ms

Dim Empty As New System.Drawing.Font("Arial", 8, FontStyle.Bold)

e.Graphics.DrawString("Empty", Empty, Brushes.Black,97, 153)

Ken



Answer this question

How can I make text flash using Graphics.DrawString

  • Kuei-yang Lo

    You could hook into the onpaint events for the form and include a system timer. With each tick set at 750 change the color of the text.



  • JTFML

    I've tried this code but, it's looking for arguments and I don't know what arguments to use. Can someone please explain this to me.

    Thanks,

    Ken

    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    number = number + 1

    Label1.Text = number

    Me.Refresh()

    If number >= 25 Then

    Timer1_Tick() 'What arguments should be used here

    number = 24

    Else

    number = number

    End If

    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    Dim formGraphics As System.Drawing.Graphics

    formGraphics = Me.CreateGraphics()

    Dim Empty As New System.Drawing.Font("Arial", 8, FontStyle.Bold)

    formGraphics.DrawString("Empty", Empty, Brushes.Blue, 175, 110)

    End Sub


  • ssmack3000

    This is where I have trouble. I don't know how to assign the timer to the string "Empty". I'm drawing the string using:

    Dim formGraphics As System.Drawing.Graphics

    formGraphics = Me.CreateGraphics()

    Dim Empty As New System.Drawing.Font("Arial", 8, FontStyle.Bold)

    formGraphics.DrawString("Empty", Empty, Brushes.Red, 175, 110)


  • SixSigmaGuy

    No fooling with Paint event needed!

    Drop a Timer to the Designer of the form where the blinking text will be. Set its Interval property to 750.

    In that form's code, select Timer1 in the upper-left combo box, and Tick in the lower-right combo box. A subroutine should be created. Add the following code to that subroutine, using the name of the blinking label or textbox instead of "Blinker", and your color instead of "BlinkColor":

    if Me.Blinker.ForeColor = Me.Blinker.BackColor Then

    Me.Blinker.ForeColor = Color.BlinkColor

    Else

    Me.Blinker.ForeColor = Me.Blinker.BackColor

    End If

    Me.Blinker.Refresh()


  • BoseMK

    I finally got it. For anyone following this thread here is the sample code and the link where I found the answer.

    ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_fxmclictl/html/8025247a-2de4-4d86-b8ab-a8cb8aeab2ea.htm

    ' This variable will be the loop counter.

    Private counter As Integer

    Private Sub InitializeTimer()

    ' Run this procedure in an appropriate event.

    counter = 0

    Timer1.Interval = 600

    Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    If counter >= 10 Then

    ' Exit loop code.

    Timer1.Enabled = False

    counter = 0

    Else

    ' Run your procedure here.

    ' Increment counter.

    counter = counter + 1

    Label1.Text = "Procedures Run: " & counter.ToString

    End If

    End Sub


  • Markus1972

    Hi Glenn,
    Being new to VB could someone please demonstrate, thanks.
    Ken

  • How can I make text flash using Graphics.DrawString