Multiline Button

On the newsgroup somebody asked how to have multiple lines of text on a .NETCF Button control. The native control supports this but the appropriate style is not set by default. The following code snippet shows how to enable this:-

private const int BS_MULTILINE = 0x00002000;
private const int GWL_STYLE = -16;

private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

public static void MakeButtonMultiline(Button b)
    IntPtr hwnd = b.Handle;
    int currentStyle = GetWindowLong(hwnd, GWL_STYLE);
    int newStyle = SetWindowLong(hwnd, GWL_STYLE, currentStyle | BS_MULTILINE);

The usage is simple, just pass the specific Button control to MakeButtonMultiline:-


Here is what the amended button looks like on the left (default appearance on the right)

The designer fully supports entering multiple lines for the Button Text property, just click the dropdown at the end of the field and it will pop up a window into which you can add linebreaks with your text.

2 thoughts on “Multiline Button”

  1. Hi. am updaing exisiting VB code to perform this function, is it possible to convert this for me , or point me to somewhere which has.


Comments are closed.