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

11
1个回答

27

您需要将按钮设置为允许多行。可以通过以下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设备上可用)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接