简体   繁体   English

如何在 vb6 中暂时显示文本和文本消失为淡入淡出

[英]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.在 Visual Basic 6 中有许多表单淡入/淡出的示例,但文本却没有。

With this code, I can display the news text after 3 seconds and then delete it.使用此代码,我可以在 3 秒后显示新闻文本,然后将其删除。 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.对于下面的示例,将 PictureBox 拖放到窗体上。 I chose to use a PictureBox instead of a Label to eliminate flickering:我选择使用 PictureBox 而不是 Label 来消除闪烁:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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