基本信息
源码名称:C# 播放器屏幕保护程序
源码大小:0.12M
文件格式:.zip
开发语言:C#
更新时间:2013-02-24
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

里面有定时器的基本用法

需要启用 Windows Media Player 功能,否则会提示【System.Runtime.InteropServices.COMException:“没有注册类】

操作步骤:控制面板>>程序>>启用或者关闭windows 功能>>选中 媒体功能>>Windows Media Player,点击确定即可


   public partial class Frm_Main : Form
    {
        int width = 0, heigh = 0;
        string strpath;
        public Frm_Main()
        {
            InitializeComponent();
            strpath = Application.StartupPath   "\\music";
        }

        private void Frm_Main_Load(object sender, EventArgs e)
        {
            this.timer1.Enabled = true;
            width = this.Width;
            heigh = this.Height;
          
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            ExitWindows();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                drowInfo(); 										//绘制屏保信息
                this.timer1.Interval = new Random().Next(800, 1600); 		//设置timer1的时间间隔
                string strname = new Random().Next(1, 4).ToString(); 		//记录随机数
                //当播放器处于空或者已停止时
                if (this.axWindowsMediaPlayer1.status == "" || this.axWindowsMediaPlayer1.status == "已停止")
                {
                    string strUrl = strpath   "\\"   strname   ".mp3";	//获取多媒体文件所处的路径
                    this.axWindowsMediaPlayer1.URL = strUrl; 	//设置播放文件的URL
                }
            }
            catch (Exception ex) 							//捕获异常
            {
                timer1.Enabled = false; 						//关闭计时器timer1
                MessageBox.Show(ex.Message); 				//弹出异常信息提示
            }
        }

        private void drowInfo()
        {
            Graphics myGraphics = this.CreateGraphics(); 			//实例化一个GDI 绘图图面类
            myGraphics.Clear(Color.Black);					//清空原有绘图面并以指定的背景色填充
            string strinfo = "歌曲播放屏幕保护";				//保存显示信息
            int x = new Random().Next(0, width - 250); 			//设置显示地点的X坐标
            int y = new Random().Next(50, heigh - 20); 			//设置显示地点的Y坐标
            myGraphics.DrawString(strinfo, new Font("华文形楷", 72, FontStyle.Bold), new SolidBrush(Color.FromArgb(new Random().Next(50, 255), new Random().Next(70, 255), new Random().Next(36, 255))), x, y); 	//绘制内容
        }

        private void ExitWindows()
        {
            this.timer1.Enabled = false;
            Application.Exit();
        }

    }