一个小问题

zhao_zps 2010-11-16 02:14:30

string x = "k";
Keys Key = Keys.k;
//怎样实现Key=Keys.(x值)
// x="h";
// Key=Keys.h;
RegisterHotKey(this.Handle, 113, 3,Key); //注册热键

怎样实现Key=Keys.(x值)
...全文
173 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Teng_s2000 2010-11-16
  • 打赏
  • 举报
回复
本身就是一个键的枚举还要x干嘛呢
Mr-Jee 2010-11-16
  • 打赏
  • 举报
回复
这是另外一个问题了

RegisterHotKey(this.Handle, 113,i,Key)不行?
那试试
RegisterHotKey(this.Handle, 113, (long)i,Key)
zhao_zps 2010-11-16
  • 打赏
  • 举报
回复

[DllImport("user32")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);

int i = 3;
RegisterHotKey(this.Handle, 113, 3,Key); //怎样把3用i代替


zhao_zps 2010-11-16
  • 打赏
  • 举报
回复

[DllImport("user32")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);

int i = 3;
RegisterHotKey(this.Handle, 113, 3,Key); //怎样把3用i代替
DataBox-MDX 2010-11-16
  • 打赏
  • 举报
回复
Keys i = (Keys)Enum.Parse(typeof(Keys), "K", true);
不懂装懂 2010-11-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 cj205 的回复:]
Keys i = (Keys)Enum.Parse(typeof(Keys), "K", true);
[/Quote]
int64 2010-11-16
  • 打赏
  • 举报
回复
ascii码
Mr-Jee 2010-11-16
  • 打赏
  • 举报
回复
Keys i = (Keys)Enum.Parse(typeof(Keys), "K", true);
nigerenz 2010-11-16
  • 打赏
  • 举报
回复
keys key = null;
string classname = "keys" ;
string functionname = x.tostring();
System.Type type = Type.GetType(classname);

if (type != null)
{
object obj = Activator.CreateInstance(type);

System.Reflection.MethodInfo method = type.GetMethod(functionname);

if (method != null)
{
key = (keys)method.Invoke(obj, new object[] {});
}
}

zhao_zps 2010-11-16
  • 打赏
  • 举报
回复
就不能具体点吗?
nigerenz 2010-11-16
  • 打赏
  • 举报
回复
用反射

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧