简体   繁体   中英

How to display text for while and Text disappears as fade in vb6

The scenario is such that the news is read from the database and each news is displayed for a few seconds and then fades out and the next news is displayed. Like breaking news on news networks like Fox news and so on..

My main problem is how the text fades out and the next news is displayed? There are many examples of form fading in/out in Visual Basic 6, but not for text.

With this code, I can display the news text after 3 seconds and then delete it. But I would like the news text to gradually fade and the next news to be displayed.

Dim EndTime As Long
Dim eee As String
EndTime = Timer + 3
Do While Timer < EndTime
    eee = CLng(EndTime - Timer)
    DoEvents
Loop
lbl(0).Caption = ""

As mentioned in the comments, the simple approach is to modify the text color. For the example below, drop a PictureBox onto a Form. I chose to use a PictureBox instead of a Label to eliminate flickering:

Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
Private Sub Form_Initialize()
   Picture1.BorderStyle = 0
   Picture1.AutoRedraw = True
End Sub

Private Sub Form_Activate()
   ShowNewsItem "This is the first news item", 3000
   ShowNewsItem "This is the second news item", 3000
   ShowNewsItem "This is the third news item", 3000
End Sub

Private Sub ShowNewsItem(ByVal NewsItem As String, ByVal HoldTime As Integer)
   Dim i As Integer

   'fade in from ButtonFace to ButtonText (gray to black)
   i = 237  'vbButtonFace
   
   Do
      Picture1.ForeColor = RGB(i, i, i)
      Picture1.CurrentX = 0
      Picture1.CurrentY = 0
      Picture1.Print NewsItem
      DoEvents
      i = i - 1
      Sleep 5
   Loop Until i < 0
   
   'hold the item
   Sleep HoldTime
   
   'fade out from ButtonText to ButtonFace (black to gray)
   i = 0  'vbButtonText
   
   Do
      Picture1.ForeColor = RGB(i, i, i)
      Picture1.CurrentX = 0
      Picture1.CurrentY = 0
      Picture1.Print NewsItem
      DoEvents
      i = i + 1
      Sleep 5
   Loop Until i > 237
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM