2011-10-05 30 views
11

Tôi muốn tạo một nút văn bản hai dòng trong Compact Framework. Tôi đã sử dụng mọi ý tưởng trong chủ đề này nhưng không thành công.Nút văn bản hai dòng trong Compact Framework

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

Nếu tôi sử dụng \n hoặc \r\n hoặc Environment.NewLine tôi nhận được hình vuông.

Tôi đang sử dụng Compact Framework 3.5.

Bất kỳ ý tưởng nào về cách tạo hộp văn bản hai dòng?

Trả lời

25

Bạn cần đặt nút để cho phép nhiều dòng. Điều này có thể đạt được với mã P/Invoke sau.

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); 
} 

Sử dụng nó như thế này:

MakeButtonMultiline(button1); 

(source, xác nhận nó hoạt động trên một thiết bị CE)

+1

Thx bạn rất nhiều. Bạn lưu ngày của tôi :)) – senzacionale

+0

Điều này cũng hoạt động với nút radio! – Robin

Các vấn đề liên quan