首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 使用 DirectX 實現視訊播放 (3):加入參考、UI 設計與 InitializeComponent 完整程式碼

     編輯:關於C語言

加入 DirectX 參考

專案右鍵「加入參考」→ .NET 頁面選 Microsoft.DirectX.AudioVideoPlayback:

UI 組件配置

  • OpenFileDialog:選擇視訊檔 (預設 *.avi)。
  • Panel:視訊播放宿主容器 (Dock=Top, 540×346)。
  • 四個 Button:開啟/播放/暫停/停止,分別繫結 Click 事件。

命名空間引用

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX.AudioVideoPlayback; // 關鍵命名空間

全域變數

private Video MyVideo = null; // 視訊播放核心物件

InitializeComponent 完整程式碼 (自動產生版本替換)

private void InitializeComponent()
{
    this.panel1 = new Panel();
    this.button1 = new Button(); // 開啟
    this.button2 = new Button(); // 播放
    this.button3 = new Button(); // 暫停
    this.button4 = new Button(); // 停止
    this.openFileDialog1 = new OpenFileDialog();
    this.SuspendLayout();
    // panel1
    this.panel1.Dock = DockStyle.Top;
    this.panel1.Location = new Point(0, 0);
    this.panel1.Name = "panel1";
    this.panel1.Size = new Size(540, 346);
    this.panel1.TabIndex = 0;
    // button1
    this.button1.Location = new Point(62, 380);
    this.button1.Name = "button1";
    this.button1.Size = new Size(80, 38);
    this.button1.TabIndex = 1;
    this.button1.Text = "開啟";
    this.button1.Click += new EventHandler(this.button1_Click);
    // button2
    this.button2.Location = new Point(165, 380);
    this.button2.Name = "button2";
    this.button2.Size = new Size(81, 38);
    this.button2.TabIndex = 1;
    this.button2.Text = "播放";
    this.button2.Click += new EventHandler(this.button2_Click);
    // button3
    this.button3.Location = new Point(268, 380);
    this.button3.Name = "button3";
    this.button3.Size = new Size(80, 38);
    this.button3.TabIndex = 1;
    this.button3.Text = "暫停";
    this.button3.Click += new EventHandler(this.button3_Click);
    // button4
    this.button4.Location = new Point(371, 380);
    this.button4.Name = "button4";
    this.button4.Size = new Size(81, 38);
    this.button4.TabIndex = 1;
    this.button4.Text = "停止";
    this.button4.Click += new EventHandler(this.button4_Click);
    // openFileDialog1
    this.openFileDialog1.DefaultExt = "avi";
    this.openFileDialog1.Filter = "視訊檔案|*.avi||";
    this.openFileDialog1.Title = "請選擇播放的 AVI 檔案";
    // Form1
    this.AutoScaleBaseSize = new Size(6, 14);
    this.ClientSize = new Size(540, 461);
    this.Controls.AddRange(new Control[] { this.button1, this.panel1, this.button2, this.button3, this.button4 });
    this.FormBorderStyle = FormBorderStyle.FixedDialog;
    this.MaximizeBox = false;
    this.Name = "Form1";
    this.Text = "Visual C#中使用DirectX實現媒體播放";
    this.Load += new EventHandler(this.Form1_Load);
    this.ResumeLayout(false);
}

設計介面預覽:

圖 03:介面設計完成畫面

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved