C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx

上传人:b****1 文档编号:1999520 上传时间:2023-05-02 格式:DOCX 页数:14 大小:342.55KB
下载 相关 举报
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第1页
第1页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第2页
第2页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第3页
第3页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第4页
第4页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第5页
第5页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第6页
第6页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第7页
第7页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第8页
第8页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第9页
第9页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第10页
第10页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第11页
第11页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第12页
第12页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第13页
第13页 / 共14页
C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx

《C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx》由会员分享,可在线阅读,更多相关《C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx(14页珍藏版)》请在冰点文库上搜索。

C#小程序桌面快捷方式启动LaunchPad 详细代码源码.docx

C#小程序桌面快捷方式启动LaunchPad详细代码源码

C#小程序桌面快捷方式启动LaunchPad详细代码源码

运行环境和编程工具:

win7+MicrosoftVisualStudio2010-c#

一、首先打开Visual2010,文件-》新建-》项目

Visualc#-》Windows–》Windows窗体应用程序

名称:

LaunchPad

解决方案名称:

LaunchPad---》确定

二、双击打开右侧的Form1

(1)添加控件GroupBox,修改右侧属性Text:

程序所在文件夹里的快捷方式,把控件拉大。

(2)在控件GroupBox上添加控件ListBox1,

修改右侧属性HorizontalScrollerbar:

True,把控件拉大。

(3)添加按钮控件button1,修改右侧属性Text:

隐藏。

三、在右侧添加自己准备的图标Icon,再添加-》类:

FZHelper.cs。

 

四、在右侧解决方案下面的“LaunchPad”-》右键属性-》左侧资源,

然后添加自己准备好的图标,自己随便找个。

我喜欢机器猫,就放了一个。

改名Icon。

五、开始编写FZHelper.cs类

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

namespaceLaunchPad

{

publicstaticclassFZHelp

{

publicstaticstringstrWeiZhui="lnk,url,pif,exe";//快捷方式尾缀,可以按照自己的需要随时添加

///

///把MessageBox.Show放到类里方便调用和修改。

///

///

publicstaticvoidMsgBox(stringneirong)

{

System.Windows.Forms.MessageBox.Show(neirong.ToString());

}

///

///获取当前APP的路径

///

///

publicstaticstringGetAppPath()

{

stringstr="";

str=AppDomain.CurrentDomain.BaseDirectory.ToString();

//str=System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;//当前APP的名称

returnstr;

}

 

#region检查尾缀是否包含类型里

///

///检查尾缀是否包含类型里

///

///文件路径

///TRUEORFALSE

publicstaticboolCheckWeiZhui(stringstrPath)

{

boolflag=false;

stringstrExtension=FZHelp.getExtension(strPath);//获取当前文件路径的尾缀

string[]ss=FZHelp.strWeiZhui.Split(',');//按照,来分割字符串到数组ss里

if(ss.Contains(strExtension))//比较尾缀是否包含在内

flag=true;

returnflag;

}

#endregion

#region获得指定路径的扩展名getExtension(stringpara)

///

///获得指定路径的扩展名(或尾缀)

///

///指定路径

///扩展名

publicstaticstringgetExtension(stringpara)

{

para.Replace("\\","");//去掉特殊符号\

intnIndex=para.LastIndexOf(".");//获取路径里所有的.的数量,以便于定位扩展名的位置

if(nIndex>0)//判断是否有.

{

para=para.Substring(nIndex+1);//加1是为了不带".",比如不是.exe

}

returnpara;

}

#endregion

 

}

}

 

六、右侧Form1.cs右键–》查看代码,开始编写

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Xml;

usingSystem.IO;

usingSystem.Diagnostics;

namespaceLaunchPad

{

publicpartialclassForm1:

Form

{

publicstringcurrentPath="";//当前所选的快捷方式完整路径

publicListstrLink=newList();//所有的快捷方式保存到这个数组里

privateboolblformMax=false;//当前窗体状态,true是显示,false是隐藏

publicForm1()

{

HideForm();//隐藏当前窗体

InitializeComponent();//初始化控件

notifyIcon1.Icon=Properties.Resources.Icon;//设置托盘图标

notifyIcon1.Text=this.Text;//设置托盘显示内容

this.Icon=Properties.Resources.Icon;//设置窗体图标

setLink(FZHelp.GetAppPath());//获取当前APP目录下所有的快捷方式并放入托盘中

}

///

///隐藏当前窗体

///

privatevoidHideForm()

{

this.ShowInTaskbar=false;

this.Hide();//窗体隐藏

this.WindowState=FormWindowState.Minimized;

}

///

///获取当前APP目录下所有的快捷方式

///

///

privatevoidsetLink(stringpath)

{

DirectoryInfoinfo=newDirectoryInfo(path);

DirectoryInfo[]dirList=info.GetDirectories();

for(inti=0;i

{

setLink(dirList[i].FullName);//如果有子目录就循环

}

foreach(FileInfofiiininfo.GetFiles())

{

//MessageBox.Show("尾缀="+FZHelp.getExtension(fii.FullName));

if(FZHelp.CheckWeiZhui(fii.FullName))

{

//MessageBox.Show(""+fii.Name+"||"+newFileInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName).Name);

if(fii.Name!

=newFileInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName).Name)//当前快捷方式的名称不能跟自己的名字相同

{

currentPath=fii.FullName;//获取所选快捷方式的名字

strLink.Add(currentPath+"文件");//添加到数组里

listBox1.Items.Add(currentPath+"文件"+fii.Name);//添加到当前窗体的ListBox1控件里

SetcontextMenuStrip(currentPath);//设置快捷方式到托盘里,并且添加事件

}

}

}

}

 

#region设置contextMenuStrip1

///

///把快捷方式放到托盘中,并为每一个快捷方式添加事件

///

///

privatevoidSetcontextMenuStrip(stringpath)

{

ToolStripMenuItemtsmItem=newToolStripMenuItem();

stringsname=path.Substring(path.LastIndexOf("\\")+1);//获取文件名

tsmItem.Text=sname;//赋值

tsmItem.Click+=newEventHandler(ToolStripMenuItemClick);//添加事件

contextMenuStrip1.Items.Add(tsmItem);

}

privatevoidToolStripMenuItemClick(objectsender,EventArgse)

{

ToolStripMenuItempara=(ToolStripMenuItem)sender;

if(currentPath!

=""&¤tPath!

=null)//路径不能为空

{

//MessageBox.Show(""+para.Text);//提示名称

try//异常处理

{

Process.Start(FZHelp.GetAppPath()+"\\"+para.Text);//运行程序

}

catch(Exception)

{

throw;

}

}

}

#endregion

 

///

///退出控件

///

///

///

privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)

{

notifyIcon1.Dispose();//释放托盘,为了在关闭程序后不再右下角显示托盘

Application.Exit();//程序退出

}

///

///显示/隐藏窗体

///

///

///

privatevoid显示隐藏ToolStripMenuItem_Click(objectsender,EventArgse)

{

if(this.blformMax==false)//如果窗体隐藏,就显示

{

this.ShowInTaskbar=true;

this.Show();

this.blformMax=true;

}

else//如果窗体显示,就隐藏

{

this.ShowInTaskbar=false;

this.Hide();

this.blformMax=false;

}

 

}

///

///双击通知栏图标显示/隐藏窗体

///

///

///

privatevoidnotifyIcon1_MouseDoubleClick(objectsender,MouseEventArgse)

{

if(this.blformMax==false)//如果窗体隐藏,就显示

{

this.ShowInTaskbar=true;

this.Show();

this.blformMax=true;

}

else//如果窗体显示,就隐藏

{

this.ShowInTaskbar=false;

this.Hide();

this.blformMax=false;

}

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

this.Hide();

this.ShowInTaskbar=false;

this.blformMax=false;

}

///

///刷新当前程序

///

///

///

privatevoid刷新ToolStripMenuItem_Click(objectsender,EventArgse)

{

Application.Restart();

}

 

}

}

以上为完整代码

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2