【问题标题】:Vertical Text on Button control VB按钮控件VB上的垂直文本
【发布时间】:2015-02-18 11:36:23
【问题描述】:

我在表单上的一个按钮需要显示这样的垂直文本:

S

T

P

我找到了涉及覆盖 Paint 的解决方案,对于这样一个简单的任务来说似乎太复杂了。我试过这个:

Private Sub LabelStopButton()
        Dim btTitle As String = "S" & vbCrLf & "T" & vbCrLf & "O" & vbCrLf & "P" & vbCrLf
        Me.btnStop.Text = btTitle
    End Sub

还尝试将 vbCrLf 替换为:vbCr、vbLf、Environment.NewLine - 无济于事,结果相同:按钮上仅显示第一个字母“S”。 See image.

使用 Visual Studio 2008(这是一个适用于旧 WinCE 6.0 设备的应用程序)。

有什么建议吗? 谢谢!

【问题讨论】:

  • 您是否将按钮垂直拉伸,以便有足够的空间显示所有字符?
  • 按钮支持多行文本。只需确保您的 Button 足够大。
  • 谢谢。我添加了一个链接来查看结果 - 控件上有足够的垂直空间(第一个“S”甚至向上移动以腾出空间......)。
  • 目标框架是什么? .NET Compact Framework 2.0?

标签: vb.net vertical-text


【解决方案1】:

这是一个现有问题的副本

https://stackoverflow.com/a/7661057/2319909

转换后的代码供参考:

您需要将按钮设置为允许多行。这可以通过以下 P/Invoke 代码来实现。

Private Const BS_MULTILINE As Integer = &H2000
Private Const GWL_STYLE As Integer = -16

<System.Runtime.InteropServices.DllImport("coredll")> _
Private Shared Function GetWindowLong(hWnd As IntPtr, nIndex As Integer) As Integer
End Function

<System.Runtime.InteropServices.DllImport("coredll")> _
Private Shared Function SetWindowLong(hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As Integer
End Function

Public Shared Sub MakeButtonMultiline(b As Button)
    Dim hwnd As IntPtr = b.Handle
    Dim currentStyle As Integer = GetWindowLong(hwnd, GWL_STYLE)
    Dim newStyle As Integer = SetWindowLong(hwnd, GWL_STYLE, currentStyle Or BS_MULTILINE)
End Sub

像这样使用它:

MakeButtonMultiline(button1)

【讨论】:

  • 请将答案标记为正确(绿色勾号)-您不需要更改标题-谢谢
【解决方案2】:

我使用以下代码在按钮上创建了垂直文本:

CommandButton1.Caption = "F" & Chr(10) & "I" & Chr(10) & "L" & Chr(10) & "T" & Chr(10) & "E" & Chr(10) & "R" & Chr(10)

Source of userform

【讨论】:

    猜你喜欢
    • 2011-03-31
    • 2013-03-07
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 2017-06-29
    • 2011-12-16
    相关资源
    最近更新 更多