用C# 自訂Window7的JumpList(捷徑清單)

來源:互聯網
上載者:User

相信用過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把之前的內容加進去,現在只能實現一個增加。 有會的高手多指點指點,多交流交流。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.