参考:自定义控件使其填充方格且自动变换大小文章,据此生成了多分屏的视频播放器。这里需要注意Controls的数组的无序性。

这里看下自定义控件的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CvNetVideo.Event;
using System.Runtime.InteropServices;
using CvNetVideo.Play;
using static CvNetVideo.UCVideo;namespace CvNetVideo
{[Guid("f3943464-829d-4bb8-8b05-10516831ceed")]//指示应用该属性的对象对COM可见[ComVisible(true)]//将事件接收接口连接到托管类[ComSourceInterfacesAttribute(typeof(MulitiControlEvents))]public partial class UserControlVideo : UserControl{#region 属性变量/// <summary>/// 选择的分屏索引/// </summary>public int SelectedIndex { set; get; }/// <summary>/// 操作的分屏索引/// </summary>private int OperationIndex;/// <summary>/// 控件原始宽度/// </summary>public int OldWidth { set; get; }/// <summary>/// 控件原始高度/// </summary>public int OldHeight { set; get; }public bool IsFullScreenInSystem { get; set; }public bool IsFullScreen = false;#endregionpublic UserControlVideo(){InitializeComponent();}# region 事件回调/// <summary>/// 全屏或退出全屏事件/// </summary>public event MulitiFullScreenEvent OnFullScreenEvent;/// <summary>/// 直播退出事件/// </summary>public event MulitiRealTimeLiveAllStopEvent OnRealTimeLiveAllStopEvent;/// <summary>/// 控件双击事件(控制全屏)/// </summary>public event MulitiControlDoubleClickEvent OnControlDoubleClickEvent;/// <summary>/// 异步远程视频回放事件/// </summary>public event MulitiAsyncRemoteVideoPlaybackEvent OnAsyncRemoteVideoPlaybackEvent;/// <summary>/// 发生某个事件触发事件/// </summary>public event MulitidglEventTrigger OnEventTrigger;/// <summary>/// 异步FTP文件上传事件/// </summary>public event MulitiAsyncFtpFileUploadEvent OnAsyncFtpFileUploadEvent;/// <summary>/// 实时视频播放超时事件/// </summary>public event MulitiRealtimeVideoOuttimeEvent OnRealtimeVideoOuttimeEvent;/// <summary>/// OCX操作优先级通知事件/// </summary>public event MulitiRealtimeVideoPriorityNotifyEvent OnRealtimeVideoPriorityNotifyEvent;/// <summary>/// 视频截图完成回调事件/// </summary>public event MulitiScreenshotCompletedEvent OnScreenshotCompletedEvent;/// <summary>/// 视频点击选中回调事件/// </summary>public event MulitiScreenSelectEvent OnScreenSelectEvent;/// <summary>/// 视频分屏重载回调事件/// </summary>public event MulitiReloadControlScreenEvent OnReloadControlScreenEvent;/// <summary>/// 全部关闭实时视频回调事件/// </summary>public event MulitiStopAllRealtimeVideoScreenEvent OnStopAllRealtimeVideoScreenEvent;/// <summary>/// 视频控件选中事件回调/// </summary>/// <param name="id"></param>public void ControlSelectdCallback(int id){this.SelectedIndex = id;this.OperationIndex = this.SelectedIndex;for (var i = 0; i < this.Controls.Count; i++){UCVideo video = this.Controls[i] as UCVideo;if (this.SelectedIndex == video.Id){video.BorderStyle = BorderStyle.Fixed3D;}else{video.BorderStyle = BorderStyle.FixedSingle;}}// 网页选中视频事件回调OnScreenSelectEvent?.Invoke(id);}/// <summary>/// 全屏回调事件回调/// </summary>/// <param name="id"></param>/// <param name="isFullScreen"></param>public void ControlFullScreenEventCallback(int id, bool isFullScreen){OpenOrCloseFullScreen(id, isFullScreen);OnFullScreenEvent?.Invoke(id, isFullScreen);}/// <summary>/// 视频关闭事件回调/// </summary>/// <param name="id"></param>public void ControlRealTimeLiveAllStopEventCallback(int id){OnRealTimeLiveAllStopEvent?.Invoke(id);}/// <summary>/// 视频双击(全屏/退出全屏)事件回调/// </summary>/// <param name="id"></param>/// <param name="isFullScreen"></param>public void ControlDoubleClickEventCallback(int id, bool isFullScreen){OnControlDoubleClickEvent?.Invoke(id, isFullScreen);}/// <summary>/// 视频回放异步远程事件回调/// </summary>/// <param name="id"></param>/// <param name="json"></param>public void ControlAsyncRemoteVideoPlaybackEventCallback(int id, string json){OnAsyncRemoteVideoPlaybackEvent?.Invoke(id, json);}/// <summary>/// 触发ID事件回调/// </summary>/// <param name="id"></param>/// <param name="eventId"></param>public void ControldglEventTriggerCallback(int id, int eventId){OnEventTrigger?.Invoke(id,eventId);}/// <summary>/// 视频异步FTP文件上传事件回调/// </summary>/// <param name="id"></param>/// <param name="json"></param>public void ControlAsyncFtpFileUploadEventCallback(int id, string json){OnAsyncFtpFileUploadEvent?.Invoke(id,json);}/// <summary>/// 实时视频播放超时事件回调/// </summary>/// <param name="id"></param>public void ControlRealtimeVideoOuttimeEventCallback(){OnRealtimeVideoOuttimeEvent?.Invoke();}/// <summary>/// 视频操作优先级通知回调/// </summary>/// <param name="id"></param>/// <param name="priority"></param>public void ControlRealtimeVideoPriorityNotifyEventCallback(int id, int priority){OnRealtimeVideoPriorityNotifyEvent?.Invoke(id,priority);}/// <summary>/// 视频截图完成事件回调/// </summary>/// <param name="id"></param>/// <param name="fileLocation"></param>public void ControlScreenshotCompletedEventCallback(int id, string fileLocation){OnScreenshotCompletedEvent?.Invoke(id,fileLocation);}/// <summary>/// 全部关闭实时视频事件回调/// </summary>public void ControlStopAllRealtimeVideoScreenEventCallback(){OnStopAllRealtimeVideoScreenEvent?.Invoke();}#endregion#region 全屏操作FullScreenObject fullScreenObject;/// <summary>/// 打开或关闭全屏/// </summary>public void OpenOrCloseFullScreen(int id,bool isOpen){int Count = (int)Math.Sqrt(this.Controls.Count);int perWidth = OldWidth / Count;int perHeight = OldHeight / Count;if (isOpen){OldWidth = this.Width;OldHeight = this.Height;if (fullScreenObject == null){if (IsFullScreenInSystem){// 系统级别的全屏fullScreenObject = new FullScreenHelper(this);}else{// 容器内的全屏fullScreenObject = new FullScreenInContainerHelper(this);}}fullScreenObject.FullScreen(isOpen);IsFullScreen = isOpen;Console.WriteLine("Entrance FullScreen Mode");// 全屏显示选择的屏幕视频窗口UCVideo fullscreenUcVideo = null;foreach (var ucVideo in this.Controls){fullscreenUcVideo = ucVideo as UCVideo;if (id == fullscreenUcVideo.Id){fullscreenUcVideo.Width = this.Width;fullscreenUcVideo.Height = this.Height;fullscreenUcVideo.Location = new Point(0, 0);fullscreenUcVideo.Visible = true;Console.WriteLine(">>>>>>>>>>>全屏Full ID=" + fullscreenUcVideo.Id);break;}}}else{if (fullScreenObject != null && IsFullScreen){fullScreenObject.FullScreen(isOpen);IsFullScreen = isOpen;// 复位全屏元素UCVideo fullscreenUcVideo = null;foreach (var ucVideo in this.Controls){fullscreenUcVideo = ucVideo as UCVideo;if (id == fullscreenUcVideo.Id){fullscreenUcVideo.Width = perWidth;fullscreenUcVideo.Height = perHeight;fullscreenUcVideo.Location = new Point(fullscreenUcVideo.X, fullscreenUcVideo.Y);fullscreenUcVideo.Visible = true;Console.WriteLine(">>>>>>>>>>>复位Full ID=" + fullscreenUcVideo.Id);break;}}this.Width = OldWidth;this.Height = OldHeight;Console.WriteLine("Exit FullScreen Mode");}}}#endregion#region 分屏处理/// <summary>/// 获取视频对象/// </summary>/// <param name="id"></param>/// <returns></returns>public UCVideo GetUCVideoById(int id){return this.Controls[id] as UCVideo;}/// 填充视频/// </summary>/// <param name="num">数量</param>public void FillUCVideo(int num){// 触发重载事件OnReloadControlScreenEvent?.Invoke();this.OperationIndex = 0;this.Controls.Clear();//填充num*num个方格,现在放置的是罗列着的for (int i = 0; i < num * num; i++){UCVideo uCVideo = new UCVideo();// 设置默认IDuCVideo.Id = i;// 注册视频选择事件uCVideo.ControlSelectdCallback = ControlSelectdCallback;// 注册视频全屏事件uCVideo.ControlFullScreenEventCallback = ControlFullScreenEventCallback;// 注册视频退出事件uCVideo.ControlRealTimeLiveAllStopEventCallback = ControlRealTimeLiveAllStopEventCallback;// 注册视频双击(全屏/退出全屏)事件uCVideo.ControlForDoubleClickEventCallback = ControlDoubleClickEventCallback;// 注册视频回放查询回调事件uCVideo.ControlAsyncRemoteVideoPlaybackEventCallback = ControlAsyncRemoteVideoPlaybackEventCallback;// 注册触发视频执行ID事件uCVideo.ControldglEventTriggerCallback = ControldglEventTriggerCallback;// 注册视频异步FTP文件上传事件uCVideo.ControlAsyncFtpFileUploadEventCallback = ControlAsyncFtpFileUploadEventCallback;// 注册实时视频播放超时事件//uCVideo.ControlRealtimeVideoOuttimeEventCallback = ControlRealtimeVideoOuttimeEventCallback;// 注册实时视频操作优先级通知事件uCVideo.ControlRealtimeVideoPriorityNotifyEventCallback = ControlRealtimeVideoPriorityNotifyEventCallback;// 注册视频截图完成回调事件uCVideo.ControlScreenshotCompletedEventCallback = ControlScreenshotCompletedEventCallback;// 是否开启桌面超时事件uCVideo.SetStartOuttimeListener(false);this.Controls.Add(uCVideo);}//定义方法,因为需要改变大小,所以单独this.LayoutUCVideos();}/// 填充视频/// </summary>/// <param name="num">数量</param>/// <param name="controlExeSelectd">选择代理函数</param>public void FillUCVideo(int num, ControlExeSelectd controlExeSelectd){this.Controls.Clear();//填充num*num个方格,现在放置的是罗列着的for (int i = 0; i < num*num; i++){UCVideo uCVideo = new UCVideo();// 设置默认IDuCVideo.Id = i;// 注册视频选择事件uCVideo.ControlSelectdCallback = ControlSelectdCallback;// 注册exe视频选择事件uCVideo.ControlExeSelectdCallback = controlExeSelectd;//注册视频全屏事件uCVideo.ControlFullScreenEventCallback = ControlFullScreenEventCallback;this.Controls.Add(uCVideo);}//定义方法,因为需要改变大小,所以单独this.LayoutUCVideos();}/// <summary>/// 布局视频/// </summary>/// <returns></returns>public void LayoutUCVideos(){OldWidth = this.Width;OldHeight = this.Height;//去除启动状态,以免开启的时候FillBtn_SizeChanged会报错if (this.Controls.Count == 0){return;}//循环多少次?计算出来int Count = (int)Math.Sqrt(this.Controls.Count);//计算每个视频的的宽度和高度int perWidth = this.Width / Count;int perHeight = this.Height / Count;int Index = 0;int X = 0, Y = 0;//竖向的循环嵌套横着的循环for (int verticalIndex = 0; verticalIndex < Count; verticalIndex++){Y = verticalIndex * perHeight;//水平向的循环for (int horizontalIndex = 0; horizontalIndex < Count; horizontalIndex++){X = horizontalIndex * perWidth;//获取要放置的方格foreach (var ucVideo in this.Controls) {UCVideo video = ucVideo as UCVideo;if (video.Id==Index){video.X = X;video.Y = Y;video.Width = perWidth;video.Height = perHeight;//设置当前方格的位置video.Location = new Point(X, Y);Console.WriteLine("=========ID:" + video.Id);break;}}//下一个方格Index++;}}}#endregion#region 控件事件/// <summary>/// 控件初始化时加载默认分屏/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void UserControlVideo_Load(object sender, EventArgs e){FillUCVideo(4);LayoutUCVideos();}private void UserControlVideo_Resize(object sender, EventArgs e){if (!IsFullScreen){LayoutUCVideos();}}#endregion}
}

关键代码处理:

  //获取要放置的方格foreach (var ucVideo in this.Controls) {UCVideo video = ucVideo as UCVideo;if (video.Id==Index){video.X = X;video.Y = Y;video.Width = perWidth;video.Height = perHeight;//设置当前方格的位置video.Location = new Point(X, Y);Console.WriteLine("=========ID:" + video.Id);break;}}

这里的id不能理解为数组下标,因为是可变的。

C# 实现多分屏视频播放-自定义控件集合无序性问题相关推荐

  1. ipad怎么和mac分屏_将Mac屏幕扩展到iPad有多好用?我甚至有了入手iPad Pro的冲动...

    这次我手机先不升 iOS 13,不够稳,但 iPadOS 更新这么多,我是绝对会升的. 手捧 11 英寸 iPad Pro 几个月,但却一直只把它当做大号 iPod Touch 的朋友在看完<i ...

  2. 苹果分屏软件_必备的优秀软件集合---Mac篇(二)

    系统类集合 PS: 打开链接时,注意墙里墙外 2019年4月29日更新: 即将下撤所有非正版链接,为每个软件增加官网链接,国外软件增加国内正版购买链接 请大家支持正版 2019年1月9号更新: 应大家 ...

  3. linux分屏显示文件行数,linux常用命令集合1

    21.查看文件行数 wc -l 文件名 # 单词数 wc -w 文件名 # 字符数 wc -m 文件名 20.查看文件内容 lesss 文件名 less demo 19.分屏显示内容 more 文件名 ...

  4. 可以分屏的软件_mac必备软件

    阿根廷华人圈 FJLEFOUR 专注于阿根廷的社会.经济.金融.商业新闻和生活等资讯信息.免费发布内容:求职招聘.超市买卖:收费发布内容:商业广告. 导读 很多使用Windows的朋友在刚刚接触到Ma ...

  5. android分屏资源适配,android7.0分屏适配

    版权声明:本文为原创文章,未经允许不得转载! 一.分屏 进入分屏模式:Android N允许用户一次在屏幕中使用两个App.用户可以左右并排/上下摆放两个App来使用,还可以左右/上下拖拽中间的分割线 ...

  6. 电脑分屏软件_一招定鲜 | 电脑实现分屏解决了办公和娱乐

    世界那么大,谢谢你来看我!!关注我你就是个网络.电脑.手机小达人 实现电脑投到电视有很多方法.有视频播放器的DLNA,需要通过网络. 现在主要介绍物理连接根据接口: 第一种方法就是通过HDMI线 通过 ...

  7. linux tmux 详细教程,Linux下的神器介绍之Tmux分屏器

    前言 我们为什么需要分屏器呢? 对于这个问题,我想大家肯定都有自己的看法. 主流的观点是这样的,对于生活在Linux下的人(开发人员.运维人员.普通爱好者)都不可避免的使用终端模拟器(比如,gnome ...

  8. java 视频监控 分屏ui_视频监控网页ActiveX视频分屏播放控件开发

    最近在搞视频监控项目,需要在网页上显示实时视频,于是网上找了很多资料研究如何在网页上播放视频,一种实现方式就是开发activex控件嵌入到网页中. 如下我将介绍如何开发一个可以分屏播放视频的activ ...

  9. 苹果如何分屏_刚刚,苹果证实,iPhone12 刘海没了!

    今年除了即将发布的 iPhone9,剩下还令我关心的苹果产品就是 iPhone12 了.哎妹:千万不要鸽了呀!毕竟要加上对 5G 的支持,而且还从英特尔换成了高通,你说能不激动么?折磨大家这么多年的信 ...

最新文章

  1. 台式计算机l小时耗电,电脑一天的耗电量是多少?不算不知道 一算吓一跳!
  2. 简单网络管理协议(SNMP)实现linux系统信息网络监控
  3. python中数据用折线图表示_用python处理文本数据
  4. [蓝桥杯][2017年第八届真题]发现环
  5. 使用winform来递归实现资源管理器
  6. java向Excel文件写入数据
  7. SpringBoot 过滤器、拦截器、监听器对比及使用场景!
  8. python中函数的入门
  9. pdf形式是什么意思
  10. 黑群晖 断电 检测有bad sector_金属你不会以为回收就能直接再用吧,不是的,这些再生金属材料检测知识,很少人知道...
  11. 29 顺时针打印矩阵(四-画图让抽象问题形象化)
  12. 【文摘】《创新者》-沃尔特·艾萨克森
  13. [免费专栏] Android安全之绕过SSL Pinning抓HTTPS数据
  14. java毕业生设计学生实验报告管理系统计算机源码+系统+mysql+调试部署+lw
  15. 三维扫描仪[10]——如何设计一台云台式扫描仪(代码详解)
  16. Creo 9.0 如何快速修改CAD坐标系?
  17. 360奇虎php,phpTrace:奇虎360开源的PHP脚本跟踪分析工具
  18. 凡诺cms2.1文件包含漏洞分析
  19. idea插件安装包下载
  20. 男人城府的修炼 男人成熟修炼

热门文章

  1. 谷歌浏览器开启导入登录密码功能
  2. R语言天气可视化应用
  3. 用letax写毕业论文-- 中英文封面
  4. MYSQL 最大连接数
  5. Python 正则表达式小结2
  6. Android闲鱼版本大全,闲鱼下载2021安卓最新版_手机app官方版免费安装下载_豌豆荚...
  7. 如何修改服务器cpu主频,服务器cpu参数怎么看【图文】
  8. 软碟通做u盘启动linux失败,使用UltraISO制作Centos7 U盘启动盘遇到的坑
  9. 【OpenCV】Pyqt5界面设计+USB摄像头
  10. 引领云数仓创新浪潮 HashData闪耀PostgreSQL中国技术大会