Mor Sagmon
Mor Sagmon

Reputation: 1035

Vertical Text on Button control VB

One of my buttons on a form needs to show vertical text like that:

S

T

O

P

I found solutions involving overriding Paint that seems too complicated for such a simple task. I tried this:

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

and also tried replacing vbCrLf with: vbCr, vbLf, Environment.NewLine - to no avail, same result: only the first letter "S" is showing on the button. See image.

Using Visual Studio 2008 (this is an app for an old WinCE 6.0 device).

Any advice? Thanks!

Upvotes: 2

Views: 3673

Answers (2)

kadrleyn
kadrleyn

Reputation: 384

I created vertical text on the button with the following codes :

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

enter image description here

Source of userform

Upvotes: 1

Sam Makin
Sam Makin

Reputation: 1556

This is a duplcate of an existing question

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

Converted code for reference:

You need to set the button to allow multiple lines. This can be achieved with following P/Invoke code.

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

Use it like this:

MakeButtonMultiline(button1)

Upvotes: 3

Related Questions