当前位置:编程学习 > VB >>

用vb写个传送带的问题,不知道怎么实现,求教

想编写一个仿传送带那样的程序,比如实现想电子屏滚动的那种,没有思路,求大神指点 电子 VB --------------------编程问答-------------------- 基本的VB图形处理+定时器就可以,具体的看看 MSDN 介绍 PictureBox 的绘图方法,逻辑上自己随便想想就可以做出来了 --------------------编程问答-------------------- 非常感谢,那如果放一段文字在传送带上呢,让它随传送带循环显示?求教 --------------------编程问答-------------------- 你新建一个标准EXE程序,然后向窗口添加一个 PictureBox控件和Timer控件,然后进入代码编辑状态,粘贴上以下代码,然后运行

Private Const DT_LEFT = &H0
Private Const DT_CALCRECT = &H400
Private Const DT_WORDBREAK = &H10
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hDC As Long, _
                                                                  ByVal lpStr As String, _
                                                                  ByVal nCount As Long, _
                                                                  lpRect As RECT, _
                                                                  ByVal wFormat As Long) As Long
Private Const YourOutText = "这是你的文本内容"
Private Const MoveCount = 10
Dim MovX As Long
Dim StringWidth As Long
Dim StringHeight As Long
Dim DrawRectWidth As Long

Private Sub Form_Load()
    Timer1.Enabled = False
    Picture1.AutoRedraw = False
    Picture1.BorderStyle = vbBSNone
    Picture1.ScaleMode = vbPixels
    Picture1.Move 0, 0, Me.Width, Me.Height
    StringWidth = GetTextWidth(Picture1.hDC, YourOutText)
    StringHeight = GetTextHeight(Picture1.hDC, YourOutText)
    DrawRectWidth = Picture1.ScaleWidth
    MovX = DrawRectWidth
    Timer1.Interval = 100
    Timer1.Enabled = True
End Sub

Private Sub Form_Resize()
    On Error Resume Next
    Picture1.Move 0, 0, Me.Width, Me.Height
End Sub

Private Sub Picture1_Resize()
    DrawRectWidth = Picture1.ScaleWidth
End Sub

Private Sub Timer1_Timer()
    Picture1.Refresh
    Picture1.CurrentX = MovX
    Picture1.CurrentY = Picture1.ScaleHeight / 2 - StringHeight / 2
    Picture1.Print YourOutText
    MovX = MovX - MoveCount
    If MovX <= -StringWidth Then
        MovX = DrawRectWidth
    End If
End Sub

Public Function GetTextWidth(ByVal dwDC As Long, _
                             ByVal StringInfo As String, _
                             Optional ByVal setHeight As Long = 0, _
                             Optional ByVal IsWordBreak As Boolean = False) As Long
   Dim RectInfo As RECT
   Dim ExecStyle As Long
   If setHeight = 0 Then
      RectInfo.Bottom = Screen.Height / 15
   Else
      RectInfo.Bottom = setHeight
   End If
   If IsWordBreak = False Then
      ExecStyle = DT_LEFT + DT_CALCRECT
   Else
      ExecStyle = DT_LEFT + DT_CALCRECT + DT_WORDBREAK
   End If
   DrawText dwDC, StringInfo, -1, RectInfo, ExecStyle
   GetTextWidth = RectInfo.Right
End Function
Public Function GetTextHeight(ByVal dwDC As Long, _
                              ByVal StringInfo As String, _
                              Optional ByVal setWidth As Long = 0, _
                              Optional ByVal IsWordBreak As Boolean = False) As Long
   Dim RectInfo As RECT
   Dim ExecStyle As Long
   If setWidth = 0 Then
      RectInfo.Right = Screen.Width / 15
   Else
      RectInfo.Right = setWidth
   End If
   If IsWordBreak = False Then
      ExecStyle = DT_LEFT + DT_CALCRECT
   Else
      ExecStyle = DT_LEFT + DT_CALCRECT + DT_WORDBREAK
   End If
   DrawText dwDC, StringInfo, -1, RectInfo, ExecStyle
   GetTextHeight = RectInfo.Bottom
End Function
--------------------编程问答-------------------- 楼上的朋友,我记得PICTUREBOX好像有个较TextHeight和TextWidth的方法…… --------------------编程问答-------------------- 有用,但是还有问题,我要的是传送带在转动的时候,比如文字,一段文字“这是你输出的文本”。当前面的被遮盖的部分有从新显示到开头的那种,就是循环显示,但是当文本的前面部分坐标小于0的时候,就会从新开始显示,但是后面还没有显示完的继续显示,也就要分段显示了,求教
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,