需要帮助将字符串var传递给需要uint类型的函数 [英] Need help passing a string var into a function requiring uint type

查看:93
本文介绍了需要帮助将字符串var传递给需要uint类型的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从两个下拉列表中选择我的全局热键,然后使用RegisterHotKey()函数中的值来设置热键。



我的下面的代码给出了一个错误,说变量是错误的数据类型。



我打算输入从我的修饰符组合框和我的热键组合框中选择的值一旦此错误是更正。



I'm trying to select my Global Hotkey from two drop down lists and then use the values in the RegisterHotKey() function to set the hotkey.

My code below gives an error saying the variables are the wrong data type.

I intend to feed in value selected from my modifier combobox and from my hotkey combobox once this error is corrected.

string keyModifer = "(uint)fsModifiers.Control";
string keyCode = "(uint)Keys.Insert";
RegisterHotKey(_hWnd, 1, keyModifer, keyCode);





谢谢...





Thank you...

引用:

知道函数的数据类型(我说我知道我的组合框字符串是错误的类型)。



我正在努力避免为每个热键组合创建一个长的switch语句。我想知道是否有办法取出我的组合框值并将其输入函数?



我不知道组合框的值是否可以是类型'fsModifiers'和'keyCode'类型。我只知道组合框的value属性有字符串和int数据类型(这两个都不会立即在这个RegisterHotKey()上工作。

know the data types for the function (I said I know my combobox strings are the wrong type).

I'm trying to avoid having to create a long switch statement for each hotkey combination. I'm wondering if there is a way to take my combobox Value and feed it into the function?

I'm not aware if a combobox Value can be of type 'fsModifiers' and of type 'keyCode'. I'm only aware of comboboxes having string and int data types for their value property (neither of which will work straight away on this RegisterHotKey().

[/ EDIT]

推荐答案

您好,



您可以创建自己的班级



Hi,

You can create your own class

public class HotKeyData
{
    public HotKeyData(string friendlyName, uint keyModifier, uint keyCode)
    {
        FriendlyName = friendlyName;
        KeyModifier = keyModifier;
        KeyCode = keyCode;
    }

    public string FriendlyName { get; set; }
    public uint KeyModifier { get; set; }
    public uint KeyCode { get; set; }
}





然后用你的班级创建一个列表



Then create a list with your class

private List<HotKeyData> comboList = new List<HotKeyData>();





例如Form_Load您将数据添加到列表中



In e.g. Form_Load you add data to the list

comboList.Add(new HotKeyData("Key1", 1, 11));
comboList.Add(new HotKeyData("Key2", 2, 12));
comboList.Add(new HotKeyData("Key3", 3, 13));
comboList.Add(new HotKeyData("Key4", 4, 14));





然后将列表绑定到组合框



Then bind the list to the combobox

comboBox1.DataSource = comboList;
comboBox1.DisplayMember = "FriendlyName";





为组合框实现一个事件。



Implement one event for the combo box.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
  HotKeyData keyData = (HotKeyData)comboBox1.SelectedItem;
  RegisterHotKey(_hWnd, 1, keyData.KeyModifier, keyData.KeyCode);
}





至少我认为这就是你想要的。



At least I think this is what you want.


这篇关于需要帮助将字符串var传递给需要uint类型的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆