繁体   English   中英

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

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

场景是这样的,从数据库中读取新闻,每个新闻显示几秒钟,然后淡出并显示下一个新闻。 就像福克斯新闻等新闻网络上的突发新闻一样。

我的主要问题是文本如何淡出并显示下一条新闻? 在 Visual Basic 6 中有许多表单淡入/淡出的示例,但文本却没有。

使用此代码,我可以在 3 秒后显示新闻文本,然后将其删除。 但我希望新闻文本逐渐消失并显示下一个新闻。

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

正如评论中提到的,简单的方法是修改文本颜色。 对于下面的示例,将 PictureBox 拖放到窗体上。 我选择使用 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