我编写了一个简单的代码来滚动表单标题栏中的文本。它工作正常,直到文本的长度达到159.然后文本切割标题栏。它没有到达标题栏的末尾,而是在标题栏的中间切断。为什么会这样?
tempheader
是一个变量,用于在表单加载时存储me.text值。
这是计时器刻度事件中的代码,间隔为100
Me.Text = " " & Me.Text
If Len(Me.Text) = 159 Then Me.Text = tempheader
答案 0 :(得分: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
答案 1 :(得分: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
最后请记住将其与表单顶部对接,我希望有人发现此代码有用。