相信用过window7 的都知道window7任务栏新增加了一些功能比如JumpList(跳转列表),如图:
这是IE8的Jumplist,现在利用Visual Studio 2010 和C#4.0 我们可以编写Code来改变Jumplist和自定义。
首先,用VS2010新建一个windowform project(注意是 .Net 4.0的架构),然后右击选择解决方案(屏幕右边)下的reference点Addreference(添加引用)这是我们要添加两个Dll文件 路径为:C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 选 PresentationCore.dll 和PresentationFramework.dll。 因为Jumplist类包含在这两个namespace下。
引用如下:
using System.Windows.Shell;
using System.IO;
核心代码如下:
private void btnAdd_Click(object sender, EventArgs e) { JumpTask jumptask = new JumpTask();//实例化一个JumpTask Object jumptask.ApplicationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe");//ApplicationPath就是应用程序路径。。 jumptask.IconResourcePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe");//程序的图标路径。 jumptask.Title = "Claculator";//标题 jumptask.Description = "Start Calculator";//描述 jumptask.CustomCategory = "New Micosoft Tools"; JumpTask jumptask1 = new JumpTask(); jumptask1.ApplicationPath = "http://www.cnblogs.com/xspaceworld/"; jumptask1.IconResourcePath = @"C:\Program Files\Internet Explorer\iexplore.exe"; jumptask1.Description = "Go To X-Space Blog"; jumptask1.Title = "Xuya's Blog"; jumptask1.CustomCategory = "Bolg Links"; JumpTask jumptask2 = new JumpTask(); jumptask2.ApplicationPath = textBox1.Text; jumptask2.IconResourcePath = textBox4.Text; jumptask2.Description = textBox2.Text; jumptask2.Title = textBox3.Text; jumptask2.CustomCategory = comboBox1.Text; JumpList jumplist = new JumpList(); jumplist.JumpItems.Add(jumptask); jumplist.JumpItems.Add(jumptask1); jumplist.JumpItems.Add(jumptask2); jumplist.Apply(); } private void btnClear_Click(object sender, EventArgs e) { JumpList jumplist1 = new JumpList(); jumplist1.JumpItems.Clear(); jumplist1.Apply(); } private void btnOpen_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; } } private void button2_Click(object sender, EventArgs e) { openFileDialog1.Filter ="ico|*.ico|exe|*.exe"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox4.Text = openFileDialog1.FileName; pictureBox1.Image =Image .FromFile (openFileDialog1 .FileName ); } } private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.Add("Bolg Links"); comboBox1.Items.Add("New Micosoft Tools"); comboBox1.SelectedIndex = 0; }
有些方面还需要改进。。
比如把之前增加过的到导出一张List,如果再要增加的话就直接调用这个List把之前的内容加进去,现在只能实现一个增加。 有会的高手多指点指点,多交流交流。
效果图: