码迷,mamicode.com
首页 > Windows程序 > 详细

141107●Winform拖动无边框窗口、播放音频、启动外部exe程序

时间:2014-11-07 06:11:36      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:winform   io   ar   os   sp   for   文件   on   art   

鼠标拖动无边框窗口

1、

        //鼠标拖动

        Point downpoint = new Point();

                   //事件,鼠标按下,获取当前坐标

        private void panel1_MouseDown(object sender, MouseEventArgs e)

        {

            downpoint.X = -e.X;

            downpoint.Y = -e.Y;

        }

 

                   //事件,鼠标移动,赋值新坐标

        private void panel1_MouseMove(object sender, MouseEventArgs e)

        {

            if (e.Button == MouseButtons.Left)

            {

                Point mouseSet = Control.MousePosition;

                mouseSet.Offset(downpoint.X, downpoint.Y);

                Location = mouseSet;

            }

 

        }

 

2、

        int x;

        int y;

                   //事件,鼠标按下,获取当前坐标

        private void Form1_MouseDown(object sender, MouseEventArgs e)

        {

            x = e.X;

            y = e.Y;

        }

                   //事件,鼠标移动,赋值新坐标

        private void Form1_MouseMove(object sender, MouseEventArgs e)

        {

            if (e.Button == System.Windows.Forms.MouseButtons.Left)

            {

                this.Left += e.X - x;

                this.Top += e.Y - y;

            }

        }

Winform中播放声音

1、添加命名空间

         using System.Media;

2、编写代码

         string sound = Application.StartupPath + "/sound/msg.wav";     //音频文件放在exe文件所在目录下的sound文件夹下。Application.StartupPath:程序exe所在的位置。

         SoundPlayer player = new SoundPlayer(sound);

         player.Load();    //把声音加载到内存

         //player.PlayLooping();    //循环播放

         player.Play();    //播放声音

 

启动外部EXE程序

         System.Diagnostics.Process.Start(@"D:\Program Files(x86)\Tencent\QQ\QQProtect\Bin\QQProtect.exe");

 

141107●Winform拖动无边框窗口、播放音频、启动外部exe程序

标签:winform   io   ar   os   sp   for   文件   on   art   

原文地址:http://www.cnblogs.com/phantom-k/p/4080339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!