现在已经获得了combobox的句柄值(hWnd),怎样修改它所选择的项?
这里 combobox 一般有两个项(少数时候是一个项或多个选择项),但是初始选择的那个是在别处定义的一个无效的项目,有效的项目排在第一位,怎么通过API设置它的选择为第一项?
设置文本框值用的是
SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, string lParam)
初次使用API请多指教,谢谢
怎样用windowAPI修改combobox的值
答案:1 悬赏:20
解决时间 2021-11-16 15:35
- 提问者网友:他是我的あ男人
- 2021-11-16 12:01
最佳答案
- 二级知识专家网友:心与口不同
- 2021-11-16 13:40
干嘛非要用API函数呢.NET里不有封装好的函数吗,下面是API函数和.NET里的方法
using System.Runtime.InteropServices;
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
IntPtr hWnd,
int Msg,
int wParam,
int lParam
);
public int CB_SETCURSEL = 334;
private void button1_Click(object sender, EventArgs e)
{
SendMessage(comboBox1.Handle, CB_SETCURSEL, 1, 0);
//或者
comboBox1.SelectedIndex = 1;
}
using System.Runtime.InteropServices;
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
IntPtr hWnd,
int Msg,
int wParam,
int lParam
);
public int CB_SETCURSEL = 334;
private void button1_Click(object sender, EventArgs e)
{
SendMessage(comboBox1.Handle, CB_SETCURSEL, 1, 0);
//或者
comboBox1.SelectedIndex = 1;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯