我想在Compact Framework中创建一个双行文本按钮。我已经在这个帖子中使用了每一个想法但没有成功。
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/626c21e0-369f-441e-b2f1-b51db633e38b
如果我使用\n
或\r\n
或Environment.NewLine
,我会得到正方形。
我正在使用Compact Framework 3.5。
关于如何制作双行文本框的任何想法?
答案 0 :(得分:25)
您需要将按钮设置为允许多行。这可以通过以下P / Invoke代码来实现。
private const int BS_MULTILINE = 0x00002000;
private const int GWL_STYLE = -16;
[System.Runtime.InteropServices.DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[System.Runtime.InteropServices.DllImport("coredll")]
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);
}
像这样使用:
MakeButtonMultiline(button1);
(source,验证它适用于CE设备)