怎么给WINFORM应用程序的快捷方式定义快捷键,是否能在程序上实现?

静_心 2018-08-31 05:53:27
怎么给WINFORM应用程序的快捷方式定义快捷键,是否能在程序上实现?

想达到的效果就是输入快捷键,能启动这个应用程序。就像安装后在桌面上的快捷方式上设置快捷键那样。希望在程序安装以后就自带这个快捷启动键,怎么实现?
...全文
537 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
静_心 2018-09-13
  • 打赏
  • 举报
回复
找到了、视图里面
静_心 2018-09-13
  • 打赏
  • 举报
回复
引用 9 楼 jing_xin 的回复:

没有自定义操作,你说的那个是什么版本的,我用的是VS2010

没有自定义操作,你说的那个是什么版本的,我用的是VS2010
静_心 2018-09-13
  • 打赏
  • 举报
回复

没有自定义操作,你说的那个是什么版本的,我用的是VS2010
  • 打赏
  • 举报
回复
VS自带的好像不能设置快捷键,都没怎么用了,VS2017默认安装都不带了,还要手动安装这个打包插件,你只想用这个加快捷键的话,可以用创建自定义操作
静_心 2018-09-13
  • 打赏
  • 举报
回复
引用 6 楼 jing_xin 的回复:
[quote=引用 5 楼 CXJ0062008 的回复:]
[quote=引用 4 楼 chb345536638 的回复:]
你用什么工具打包的?一般的打包工具本来就可以快捷键的,比如Inno Setup设置下HotKey 就可以了,安装完成看快捷方式的属性,有就成功了
赞同,有些打包工具本身就支持,如果没有,以上代码一样可以用, WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(你的快捷方式路径);//创建快捷方式对象
shortcut.Hotkey = "Ctrl+Alt+T";//热键
shortcut.Save();//保存快捷方式[/quote]

就.NET自带的那个。里面没有对HOTKEY的设置[/quote]

这段放在哪里?自带的那个是没法写入程序的。
静_心 2018-09-13
  • 打赏
  • 举报
回复
引用 5 楼 CXJ0062008 的回复:
[quote=引用 4 楼 chb345536638 的回复:]
你用什么工具打包的?一般的打包工具本来就可以快捷键的,比如Inno Setup设置下HotKey 就可以了,安装完成看快捷方式的属性,有就成功了
赞同,有些打包工具本身就支持,如果没有,以上代码一样可以用, WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(你的快捷方式路径);//创建快捷方式对象
shortcut.Hotkey = "Ctrl+Alt+T";//热键
shortcut.Save();//保存快捷方式[/quote]

就.NET自带的那个。里面没有对HOTKEY的设置
我是小数位 2018-09-05
  • 打赏
  • 举报
回复
引用 4 楼 chb345536638 的回复:
你用什么工具打包的?一般的打包工具本来就可以快捷键的,比如Inno Setup设置下HotKey 就可以了,安装完成看快捷方式的属性,有就成功了
赞同,有些打包工具本身就支持,如果没有,以上代码一样可以用, WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(你的快捷方式路径);//创建快捷方式对象
shortcut.Hotkey = "Ctrl+Alt+T";//热键
shortcut.Save();//保存快捷方式
  • 打赏
  • 举报
回复
你用什么工具打包的?一般的打包工具本来就可以快捷键的,比如Inno Setup设置下HotKey 就可以了,安装完成看快捷方式的属性,有就成功了
静_心 2018-09-04
  • 打赏
  • 举报
回复
楼上,这段代码如何用?
我是打包后生成的快捷方式,这段代码能结合用??
我是小数位 2018-09-03
  • 打赏
  • 举报
回复
 public static void CreateShortcut(string directory, string shortcutName, string targetPath,
string description = null, string iconLocation = null)
{
if (!System.IO.Directory.Exists(directory))
{
System.IO.Directory.CreateDirectory(directory);
}

string shortcutPath = Path.Combine(directory, string.Format("{0}.lnk", shortcutName));
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);//创建快捷方式对象
shortcut.TargetPath = targetPath;//指定目标路径
shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);//设置起始位置
shortcut.WindowStyle = 1;//设置运行方式,默认为常规窗口
shortcut.Description = description;//设置备注
shortcut.Hotkey = "Ctrl+Alt+S";//热键
shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation;//设置图标路径
shortcut.Save();//保存快捷方式
}

/// <summary>
/// 创建桌面快捷方式
/// </summary>
/// <param name="shortcutName">快捷方式名称</param>
/// <param name="targetPath">目标路径</param>
/// <param name="description">描述</param>
/// <param name="iconLocation">图标路径,格式为"可执行文件或DLL路径, 图标编号"</param>
/// <remarks></remarks>
public static void CreateShortcutOnDesktop(string shortcutName, string targetPath,
string description = null, string iconLocation = null)
{
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//获取桌面文件夹路径
CreateShortcut(desktop, shortcutName, targetPath, description, iconLocation);
}

添加com引用Windows Script Host Object Model
王志威丶 2018-09-03
  • 打赏
  • 举报
回复
这个貌似是要去修改注册表的把

110,548

社区成员

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

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

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