0

我编写了一个简单的代码来滚动表单标题栏中的文本。它工作正常,直到文本的长度达到 159。之后,标题栏中的文本剪切。它没有到达标题栏的末尾,而是在标题栏的中间切断。为什么会这样? tempheader是一个在表单加载时存储 me.text 值的变量。

这是间隔为 100 的计时器滴答事件中的代码

 Me.Text = " " & Me.Text
        If Len(Me.Text) = 159 Then Me.Text = tempheader
4

2 回答 2

0

尝试这个 ..

Dim g As Graphics = Me.CreateGraphics()

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

    sPace &= " "
    Me.Text = sPace & Me.Text
    If g.MeasureString(Me.Text, Me.Font).Width >= Me.Width Then
        Me.Text = tempheader
        sPace = ""
    End If

End Sub
于 2013-06-19T17:11:47.920 回答
0

大声笑我知道这是一篇旧帖子,但我在寻找其他内容时遇到了它,我只是使用自定义标题栏来滚动文本。只需创建一个空表单,双击它删除所有代码并从下面添加代码。返回并从项目中删除表单并将其保存为 dll。您只需将其导入回来并将其添加到您的工具栏,您就可以在任何项目中使用它。


Imports System.Drawing
Public Class CustomTitlebar
Inherits Windows.Forms.Panel
  Public Sub ColourTitleText(ByRef panelBG As Color, ByRef txtBG As Color, ByRef txtFC As Color)
    Dim textbox1 As New Windows.Forms.TextBox
    Dim Psize As New Point(26, 200)
    Me.Size = New Point(26, 200)
    Me.BackColor = panelBG
    Me.BorderStyle = Windows.Forms.BorderStyle.None
    Me.Dock = Windows.Forms.DockStyle.Top
    Me.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    textbox1.Name = "Textbox1"
    textbox1.BackColor = txtBG
    If Not txtFC = Nothing Then
        textbox1.ForeColor = txtFC
    End If
    textbox1.BorderStyle = Windows.Forms.BorderStyle.None
    textbox1.Size = New Size(Psize.X - 4, 20)
    textbox1.Location = New Point(3, 3)
    textbox1.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    textbox1.Multiline = False
    textbox1.Text = "Coded by tHE_alCHMist 2010"
    Me.Controls.Add(textbox1)
  End Sub
End Class

将其放入计时器“CustomTitlebar1.Text = MarqueeLeft(CustomTitlebar1.Text)”


然后把这个函数放在某个地方

Public Function MarqueeLeft(ByVal Text As String)
    Dim Str1 As String = Text.Remove(0, 1)
    Dim Str2 As String = Text(0)
    Return Str1 & Str2
End Function

最后记得把它停靠在表单的顶部,我希望有人觉得这段代码有用。

于 2016-12-21T05:50:54.590 回答