紧凑框架中的两行文本按钮

本文关键字:两行 文本 按钮 框架 | 更新日期: 2023-09-27 18:10:32

我想在Compact Framework中创建一个两行文本按钮。我用了这个帖子里的每一个想法,但都没有成功。

http://social.msdn.microsoft.com/forums/en us/winforms/thread/626c21e0 - 369 f - 441 e - b2f1 b51db633e38b

如果我用'n'r'nEnvironment.NewLine,我得到正方形

我使用的是Compact Framework 3.5.

你知道如何制作一个两行文本框吗?

紧凑框架中的两行文本按钮

您需要设置按钮以允许多行。这可以通过以下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);

(源代码,已在CE设备上验证)