2011-10-05 17 views
11

में दो-पंक्ति पाठ बटन मैं कॉम्पैक्ट फ्रेमवर्क में दो-पंक्ति टेक्स्ट बटन बनाना चाहता हूं। मैंने इस धागे में हर विचार का उपयोग किया है लेकिन सफलता के बिना।कॉम्पैक्ट फ्रेमवर्क

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

अगर मैं \n या \r\n या Environment.NewLine का उपयोग मैं वर्गों मिलता है।

मैं कॉम्पैक्ट फ्रेमवर्क 3.5 का उपयोग कर रहा हूं।

दो-पंक्ति टेक्स्ट बॉक्स बनाने के तरीके पर कोई विचार?

उत्तर

25

आपको एकाधिक लाइनों को अनुमति देने के लिए बटन सेट करने की आवश्यकता है। यह निम्नलिखित पी/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, सत्यापित यह एक सीई डिवाइस पर काम करता है)

+1

Thx बहुत-बहुत। आप मेरा दिन बचाओ :)) – senzacionale

+0

यह रेडियो बटन के साथ भी काम करता है! – Robin

संबंधित मुद्दे