Click und Kontextmenü auf DirectX Video

ratho

Mitglied
Hallo,

Ich habe in einem Form eine PictureBox eingebaut und zeige dort ein Video an.
Wie kann ich nun bei einem Click auf das Video dieses starten oder mit einem Rechts-Klick ein Kontextmenü öffnen?

Das Click-Event der PictureBox reagiert nicht :mad:

Code:
using Microsoft.DirectX.AudioVideoPlayback;
......
Video video = null;
......
video = new Video("C:\test.mpg", false);
video.CurrentPosition = 1;
video.Owner = thumbPictureBox;
video.Pause();

Danke für eure Hilfe!
 
Du brauchst das Klick Event nicht abzufangen. Höchstens wenn Du wegen bestimmter Abhängigkeiten das ContextMenu de/aktivieren willst.
Erstell ein Context Menu und weise es der PictureBox zu.
Code:
pbxVideo.ContextMenu = MyContextMenu
(Das sollte im VS kein Problem sein. Hast ja über die IDE direkt Zugriff auf die Eigenschaften)

Übrigens Panels eignen sich auch dafür.

MfG cosmo
 
Hallo,

die Event's der Picturebox werden aber nicht ausgeführt!

Anscheinend liegt die Picturebox unter dem DirectX Video - auf alle Fälle geht's nicht!
 
Hallo,

ich hab's jetzt mit einem Panel versucht - aber leider auch ohne Erfolg :(

Hier mein Code:
Code:
/*
 * Created by SharpDevelop.
 * User: Thorsten
 * Date: 11.01.2005
 * Time: 17:45
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;

namespace test
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		Video video = null;
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			video = new Video(@"D:\Test.mpg", false);
			video.CurrentPosition = 1;
			video.Owner = panel1;
			video.Play();
			
		}
		
		[STAThread]
		public static void Main(string[] args)
		{
			Application.Run(new MainForm());
		}
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.panel1 = new System.Windows.Forms.Panel();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Location = new System.Drawing.Point(8, 8);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(288, 232);
			this.panel1.TabIndex = 1;
			this.panel1.Click += new System.EventHandler(this.Panel1Click);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(304, 246);
			this.Controls.Add(this.panel1);
			this.Name = "MainForm";
			this.Text = "MainForm";
			this.ResumeLayout(false);
		}
		#endregion
		void Panel1Click(object sender, System.EventArgs e)
		{
			MessageBox.Show("panel");
		}
		
	}
}

Ist nur ein Fenster mit einem Panel und wenn man darauf klickt soll eine MessageBox aufgehen.

Kannst Du das mal probieren ob's bei dir funktioniert - oder hab ich was falsch gemacht ?

Danke!
 
  • Das Klick-Event Funkioniert!
  • Ich finde leider keinen Verweis auf Microsoft.DirectX.
    Bei mir wird nur
    Microsoft.CSharp
    Microsoft.VisualBasic
    Microsoft.Win32
    angezeigt
    Denke mal Du verwendest DX9 oder eine DLL? Gib mir mal bitte einen Tip.
    Ich habe bisher nur die QuarzTypeLib für Videos verwendet. Ansich sieht das fast genau so aus wie Du es machst.
Code:
video.Owner = panel1;
Auf meinenem ArbeitsRechner ist aber kein DX9 installiert. Wenn ich heut noch dazu komme werd ich's mal downloaden und installiren. Wenn nicht, probier ich das heut abend bei mir @home und versuch mal ein Video wiederzugeben.


MfG cosmo
 
Hallo,

betreffend DirectX

Du mußt entweder das SDK installieren oder wenn du das "normale" DirectX entpackst findest du eine Datei mit dem Namen "ManagedDX.CAB" diese Entpacken und installieren (ist die Erweiterung für DirectX und NET - wird im Standard nicht installiert)

Schon mal danke für die Hilfe!
 
Hallo,

hab jetzt eine Lösung gefunden :)

Ich fange das MouseDown Event und nicht das Click Event ab und Prüfe dann auf die Linke Maustaste.

Das MouseDown Event wird anscheinend immer ausgelöst - warum das Click Event nicht funktioniert ? keine Ahnung - aber wie heist es so schön: it's not a bug, it's a feature :)
 
Hi!

Und sorry für die späte Meldung. Ich hatte blöderweise das Abonnement gelöscht.
Alles was Du wolltest funktioniert.

Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;

namespace Video_Test {
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form {
		private System.Windows.Forms.Panel panel1;
		Video video = null;

		public MainForm() {
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();

			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			OpenFileDialog ofdVideoLocation = new OpenFileDialog();
			ofdVideoLocation.Filter = "Video Dateien (*.avi)|*.avi|Alle Dateien (*.*)|*.*";
			ofdVideoLocation.Title = "Video laden";

			if ( ofdVideoLocation.ShowDialog() == DialogResult.OK ){
				try{
					video = new Video( ofdVideoLocation.FileName, false );
					video.CurrentPosition = 1;
					video.Owner = panel1;
					video.Play();

				}catch ( Exception ex ){
					MessageBox.Show( ex.ToString(),"Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error );
				}
			}
		}

		[STAThread]
		public static void Main(string[] args) {
			Application.Run(new MainForm());
		}

		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.panel1 = new System.Windows.Forms.Panel();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(304, 228);
			this.panel1.TabIndex = 1;
			this.panel1.MouseDown += new MouseEventHandler(panel1_MouseDown);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(304, 228);
			this.Controls.Add(this.panel1);
			this.Name = "MainForm";
			this.Text = "MainForm";
			this.ResumeLayout(false);

		}
		#endregion

		private void panel1_MouseDown(object sender, MouseEventArgs e) {
			if ( e.Button == MouseButtons.Left )
				MessageBox.Show("!");
		}
	}
}

MfG cosmo
 
Zuletzt bearbeitet:
Halt mal ich hab auch grad erst bemerkt das sobald das Video Objekt der Owner des Panels ist, das OnClick-Event nicht ausgeführt wird.
Dann muss es eben so gemacht werden wie Du es beschrieben hast.
Hab den Code oben korrigiert.

MfG cosmo
 
Zurück