对,不知道你说的是listbox还是combobox,这两个命令是不同的。 按照combobox回答一下 const int CB_GETCOUNT = 0x0146; const int CB_GETLBTEXT = 0x0148; const int CB_SETCURSEL = 0x014e; [DllImport("user32.dll")] static extern int SendMessage(IntPtr hwnd, int msg, int wParam, int lParam); //获得选项数量 int count = SendMessage(comboBox1.Handle, CB_GETCOUNT, 0, 0); //获得指定索引的选项内容,索引index byte[] b = new byte[10]; fixed (byte* p = b) { SendMessage(comboBox1.Handle, CB_GETLBTEXT, index, (int)p); } string s = Encoding.Unicode.GetString(b); //选择指定索引的选项,索引index SendMessage(comboBox1.Handle, CB_SETCURSEL, index, 0);
按照combobox回答一下 const int CB_GETCOUNT = 0x0146;
const int CB_GETLBTEXT = 0x0148;
const int CB_SETCURSEL = 0x014e;
[DllImport("user32.dll")]
static extern int SendMessage(IntPtr hwnd, int msg, int wParam, int lParam); //获得选项数量
int count = SendMessage(comboBox1.Handle, CB_GETCOUNT, 0, 0);
//获得指定索引的选项内容,索引index
byte[] b = new byte[10];
fixed (byte* p = b)
{
SendMessage(comboBox1.Handle, CB_GETLBTEXT, index, (int)p);
}
string s = Encoding.Unicode.GetString(b);
//选择指定索引的选项,索引index
SendMessage(comboBox1.Handle, CB_SETCURSEL, index, 0);
指针!明确的告诉大家,C#是有指针的!!