zoukankan      html  css  js  c++  java
  • ●Winform拖动无边框窗口、播放音频、启动外部exe程序

    鼠标拖动无边框窗口

    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)TencentQQQQProtectBinQQProtect.exe");

  • 相关阅读:
    centos7安装kubenetes
    用户密码字典
    curl使用
    docker部署rabbitmq集群
    记一次使用docker搭建fastdfs服务的过程
    filebeat删除多余标签
    Python format格式化输出
    python3 统计NGINX pv uv 最多IP访问
    linux修改网卡名为eth0
    模式查找
  • 原文地址:https://www.cnblogs.com/phantom-k/p/4080339.html
Copyright © 2011-2022 走看看