2011-10-05 57 views

回答

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設備上)

+1

THX你了。你節省了我的一天:)) – senzacionale

+0

這也適用於單選按鈕! – Robin