WPF中是没有托盘控件的,可是,有时候就得用到托盘,这时候怎么办,这时候,就要自定义控件,这里就看看自定义控件,这里是我整理出来的代码,
public NotifyIcon notifyIcon = null; //定义个NotifyIcon类,这是托盘类,需要自己写属性和事件,有些麻烦,咳咳
//设置托盘的各个属性
notifyIcon = new NotifyIcon();
notifyIcon.BalloonTipText = "V_John播放器放到这里啦!";//这是气球提示的文本
notifyIcon.BalloonTipTitle = "小小提示";//这是气球提示的标题
notifyIcon.Icon = new System.Drawing.Icon(@"../../Images/Music.ico");//设置托盘的图标
notifyIcon.Visible = true;//设置是否显示
notifyIcon.ShowBalloonTip(2000);//气泡显示时间
notifyIcon.Text = "V_John播发器base6.0.2 \n by: 503115254";
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);//托盘鼠标单击事件
//设置菜单项,就是右键的时候,出现的选择列表
System.Windows.Forms.MenuItem ShowMain = new System.Windows.Forms.MenuItem("显示");
//MenuItem Setting = new MenuItem("Setting", new MenuItem[] { ShowMain });//这样,就把ShowMain变成是Setting是子选项;
System.Windows.Forms.MenuItem playPtevMusic = new System.Windows.Forms.MenuItem("上一曲");
System.Windows.Forms.MenuItem playPause = new System.Windows.Forms.MenuItem("暂停");
System.Windows.Forms.MenuItem playNextMusic = new System.Windows.Forms.MenuItem("下一曲");
System.Windows.Forms.MenuItem aboutMe = new System.Windows.Forms.MenuItem("关于我");
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");
exit.Click += new EventHandler(exit_Click);//这些事件,不是我一个一个字打出来的,有提示的,很好辨认,我要点击事件,当然是Click事件咯,然后输入+= 就自动提示出来了,就不要管了,自动给你来个方法,有必要的话,自己到给你好的方法里面去修改代码
ShowMain.Click += new EventHandler(ShowMain_Click);
playPtevMusic.Click += new EventHandler(playPtevMusic_Click);
playPause.Click += new EventHandler(playPause_Click);
playNextMusic.Click += new EventHandler(playNextMusic_Click);
aboutMe.Click += new EventHandler(aboutMe_Click);
//关联托盘控件
System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { ShowMain, playPtevMusic, playPause, playNextMusic, aboutMe, exit };
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
嗯嗯,这就差不多了,如果需要别的,就自己添加吧。。。