1 public partial class Form1: Form
2 {
3 // combobox只读代码
4 [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
5 public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
6 int GW_CHILD = 5;
7 [DllImport("user32.dll", CharSet = CharSet.Auto)]
8 public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
9 public const int EM_SETREADONLY = 0xcf;
10 //构造函数
11 public Form1()
12 {
13 InitializeComponent();
14 IntPtr editHandle = GetWindow(this.comboBox1.Handle, GW_CHILD);
15 SendMessage(editHandle, EM_SETREADONLY,1,0); //第四个参数"0"代表只读,设置为"1"为可编辑
16 }
17 }