1

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

小号

我发现涉及覆盖 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”。见图片

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

有什么建议吗?谢谢!

4

2 回答 2

2

这是现有问题的重复

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)
于 2015-02-18T13:17:34.297 回答
0

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

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

在此处输入图像描述

用户表单的来源

于 2022-02-02T21:04:56.877 回答