Display Two Lines of Text in Button.Text

  • Thread starter Thread starter sheeeng
  • Start date Start date
S

sheeeng

Hi all,

Is there anyone know how to display two lines of text within the
button.text?

Thanks in advance.
 
I don't know if it would work, but try setting the button's multiline
property to TRUE and use a line break in your string
 
Hi,

In CF you don't have multiline property on buttons. You have to use
platform invoke to set button as multiline. Below my code.

public class MultilineButton
{
private MultilineButton()
{
}

[DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int
nIndex, int dwNewLong);

private const int GWL_STYLE = -16;
private const int BS_CENTER = 0x00000300;
private const int BS_VCENTER = 0x00000C00;
private const int BS_MULTILINE = 0x00002000;

public static void
SetButtonAsMultiline(System.Windows.Forms.Button c)
{
c.Text = c.Text.Replace("\r\n", "\r").Replace("\n\r",
"\r").Replace("\n", "\r");
int style = GetWindowLong(c.Handle, GWL_STYLE);
SetWindowLong(c.Handle, GWL_STYLE, (style | BS_CENTER |
BS_VCENTER | BS_MULTILINE));
c.Refresh();
}
}


Call SetButtonAsMultiline and pass your button as parameter. In text
property set line break as "\n" or "\r" or "\r\n" or "\n\r" and that's it.
 
Hi,

In CF you don't have multiline property on buttons. You have to use
platform invoke to set button as multiline. Below my code.

public class MultilineButton
{
private MultilineButton()
{
}

[DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int
nIndex, int dwNewLong);

private const int GWL_STYLE = -16;
private const int BS_CENTER = 0x00000300;
private const int BS_VCENTER = 0x00000C00;
private const int BS_MULTILINE = 0x00002000;

public static void
SetButtonAsMultiline(System.Windows.Forms.Button c)
{
c.Text = c.Text.Replace("\r\n", "\r").Replace("\n\r",
"\r").Replace("\n", "\r");
int style = GetWindowLong(c.Handle, GWL_STYLE);
SetWindowLong(c.Handle, GWL_STYLE, (style | BS_CENTER |
BS_VCENTER | BS_MULTILINE));
c.Refresh();
}
}


Call SetButtonAsMultiline and pass your button as parameter. In text
property set line break as "\n" or "\r" or "\r\n" or "\n\r" and that's it.
 
Back
Top