将Click事件处理函数添加到C#Video - Windows窗体 [英] Adding a Click event handler function to a C# Video - Windows Forms

查看:110
本文介绍了将Click事件处理函数添加到C#Video - Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前正在使用Visual Studio Express 2012中的C#Windows窗体应用程序。



我有一个视频,其父级设置为Panel与视频完全相同的大小(基本上是视频的容器)。我所追求的是具有点击事件处理程序的视频,因此当点击视频上的任何区域时,将执行某个功能。



但是,Video对象似乎没有内置的Click事件处理程序。我已经尝试了很多方法来解决这个问题,包括将透明的pictureBox和Panel放在视频顶部并使用自己的click事件,但这似乎不起作用。



有人可以告诉我一个方法吗?



非常感谢





---------编辑---------



代码如下所示。我想控制点击video1时会发生什么



Hi, I am currently working on a C# Windows Forms Application within Visual Studio Express 2012.

I have a video, which has it's parent set to a Panel the exact same size as the video (Basically a container for the video). What I am after is the video to have a click event handler so a certain function is performed when any area on the video is clicked.

However there does not seem to be a built in Click event handler for the Video object. I have tried a number of ways to get around this including placing a transparent pictureBox and Panel placed on top of the video with its own click event however this does not seem to work.

Can anyone advise me a way around this please?

Many Thanks


---------edit---------

Code shown below as requested. I want to control what happens when video1 is clicked

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media; 
using Microsoft.DirectX.DirectSound; 
using Microsoft.DirectX.AudioVideoPlayback;

namespace videoApplication
{
	public partial class Videos : Form
    {
		Video video1;
		Panel videosPanel;
		
		public Videos()
        {
            InitializeComponent();
        }
		
		private void Videos_Load(object sender, EventArgs e)
		{
			//Get the video file path
		    var vffilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            vffilePath = vffilePath.Substring(0, vffilePath.Length - 15) + "/Video1.wmv";
			
			//Load the video and set parent to panel
			video1 = new Video(filePath);
            video1.Owner = videosPanel;
            video1.Size = new Size(500, 500);
            videosPanel.Size = new Size(500, 500);
			
			//Start playing video automatically
            video1.Play();		
		}
	}
}

推荐答案

我建​​议你看看ContextMenuStrip [ ^ ],其中< b>表示与之关联的任何控件的快捷菜单。



如何做到这一点,这非常简单。在应用程序中添加上下文菜单后,您应该使用控件的属性。但是,请查看此处 [ ^ ]。



此处提供了一个小小的例子。[ ^ ]。



希望这个很多信息对你有用。



-KR
I would suggest you to look at ContextMenuStrip[^], which represents a shortcut menu for the any control associated with it.

And how to do that, that is pretty simple. You should play around with the property of the control after adding context menu in your application. But still, look at here[^].

A small little tiny example of it is given over here.[^].

Hope this much info could be useful to you.

-KR


这篇关于将Click事件处理函数添加到C#Video - Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆