串口通讯系列三-指定某一控件全屏

/*========================================
 某一控件全屏
 按ESC退出全屏
 视频重复播放
 屏蔽鼠标双击及右键功能
 ========================================*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsVideo
{
    public partial class Form1 : Form,IMessageFilter {
       
        public Form1()
        {
            InitializeComponent();
            Application.AddMessageFilter(this);//监听系统消息
            
        }
        //打开视频目录
        string path = System.Windows.Forms.Application.StartupPath + "\\Video\\" + "1灯" + ".avi";
        private void Form1_Load(object sender, EventArgs e)
        {
            InitVedio();
            InitEvent();
        }
        
        //初始化播放控件的视频文件地址及播放控件
        private void InitVedio() {
            axWindowsMediaPlayer1.URL = path;//视屏地址
            axWindowsMediaPlayer1.Ctlcontrols.play();//播放视频
            this.axWindowsMediaPlayer1.uiMode = "none";//播放界面模式只有播放部分,没有控制条
            this.axWindowsMediaPlayer1.stretchToFit = true;//非全屏状态时是否伸展到最佳大小
            this.FormBorderStyle = FormBorderStyle.None;//窗体边框的样式
            this.WindowState = FormWindowState.Maximized;//窗体最大化
            Rectangle rect = Screen.GetWorkingArea(this);//获取最大化区域
            this.axWindowsMediaPlayer1.ClientSize = new Size(rect.Width, rect.Height);//工作区域
            this.axWindowsMediaPlayer1.Dock = DockStyle.Fill;//Dock某个子窗体最大
            this.axWindowsMediaPlayer1.BringToFront();//是控件置前
        }
        //实现循环播放
        protected void InitEvent() {
            axWindowsMediaPlayer1.StatusChange += new EventHandler(axWindowsMediaPlayer1_StatusChange);
        }

         //通过控件的状态改变,来实现视频循环播放  
         protected void axWindowsMediaPlayer1_StatusChange(object sender, EventArgs e) {
        
         //判断视频是否已停止播放  
         if((int)axWindowsMediaPlayer1.playState == 1) {
                //停顿2秒钟再重新播放 System.Threading.Thread.Sleep(2000); 
                //System.Threading.Thread.Sleep(50);
                //重新播放  
                axWindowsMediaPlayer1.Ctlcontrols.play();
          }
         }

        //按Esc键退出全屏//重写ProcessCmdKey的方法  
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            int WM_KEYDOWN = 256;
            int WM_SYSKEYDOWN = 260;
            if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
            {
                switch (keyData)
                {
                    case Keys.Escape:
                        this.axWindowsMediaPlayer1.Dock = DockStyle.None;//Dock某个子窗体取消置前,恢复到窗体内
                        this.FormBorderStyle = FormBorderStyle.Sizable;//可调整大小的边框
                        this.WindowState = FormWindowState.Normal;//正常大小
                        this.ClientSize = new Size(300, 300);//设置窗体工作区的大小
                        this.axWindowsMediaPlayer1.Location = new Point(12, 13);//初始位置
                        this.axWindowsMediaPlayer1.ClientSize = new Size(260, 206);//即是控件的原始尺寸

                        //this.Close();//esc关闭窗体
                        break;
                }
            }
            return false;
        }
        //屏蔽鼠标双击及右键
        //添加接口:IMessageFilter
        //构造函数中添加:Application.AddMessageFilter(this);
        bool IMessageFilter.PreFilterMessage(ref Message myMessage) {
            //屏蔽鼠标双击
            if(myMessage.Msg == 515) {
                return true;
            }
            //屏蔽鼠标右键
            else if(myMessage.Msg >= 516 && myMessage.Msg <= 517) {
                return true;
            } else {
                return false;
            }
        }
    /*
        private void button1_Click(object sender, EventArgs e) {
            axWindowsMediaPlayer1.Ctlcontrols.next();//播放下一视频,预留
        }*/
    }
    
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值