初學VBNET事例~~

播放聲音文件爲例:
Imports System.ComponentModel ''''引用 族名 System.ComponentModel
Imports System.Drawing ''''引用族名 System.Drawing
Imports System.WinForms ''''引用族名 System.WinForms
''''引用族名的目的是在調用他的子類時不需要寫出族名,如system.drawing.color寫成color
Public Class Form1
    Inherits System.WinForms.Form '''' Inherits是從已有的一個類繼承,得到這個類已定義的方法
 
    Public Sub New()
        MyBase.New() ''''mybase是指代父類 mybase.new是調用父類的new過程,new是新建一個對象,對象是存在內存的,類是並不存在內存的
 
        Form1 = Me ''''這樣,下面的me關鍵字 就被認定爲form1
 
        InitializeComponent() ''''這下面的代碼是在新建一個form1的實例時執行的初始化動作
        Call me_load() ''''這是自定義的一個子過程
       
    End Sub
 
    ''''Form overrides dispose to clean up the component list.
    Overrides Public Sub Dispose()
        AxMMControl1.Command = "close" ''''關閉聲音資源,這個代碼一定要放在dispose過程的前面
        MyBase.Dispose() ''''dispose是清除對象
        components.Dispose() ''''清空組件
    End Sub
   
    ''''下面的代碼是對屬性的描述,是系統自已生成的,不要隨意修改
#Region " Windows Form Designer generated code "
   
    ''''Required by the Windows Form Designer
    Private components As System.ComponentModel.Container
    Private WithEvents Button3 As System.WinForms.Button
    Private WithEvents Button2 As System.WinForms.Button
    Private WithEvents Button1 As System.WinForms.Button
    Private WithEvents AxMMControl1 As AxMCI.AxMMControl
   
    Dim WithEvents Form1 As System.WinForms.Form
   
    ''''NOTE: The following procedure is required by the Windows Form Designer
    ''''It can be modified using the Windows Form Designer. 
    ''''Do not modify it using the code editor.
    Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
       
        Me.components = New System.ComponentModel.Container()
        Me.Button1 = New System.WinForms.Button()
        Me.AxMMControl1 = New AxMCI.AxMMControl()
        Me.Button3 = New System.WinForms.Button()
        Me.Button2 = New System.WinForms.Button()
       
        AxMMControl1.BeginInit()
       
        ''''@design Me.TrayHeight = 0
        ''''@design Me.TrayLargeIcon = False
        ''''@design Me.TrayAutoArrange = True
        Button1.Location = New System.Drawing.Point(8, 8)
        Button1.Size = New System.Drawing.Size(80, 32)
        Button1.TabIndex = 1
        Button1.Text = "Button1"
       
        AxMMControl1.OcxState = CType(resources.GetObject("AxMMControl1.OcxState"), System.WinForms.AxHost.State)
        AxMMControl1.TabIndex = 0
        AxMMControl1.Size = New System.Drawing.Size(236, 33)
        AxMMControl1.Location = New System.Drawing.Point(32, 56)
       
        Button3.Location = New System.Drawing.Point(208, 8)
        Button3.Size = New System.Drawing.Size(80, 32)
        Button3.TabIndex = 3
        Button3.Text = "Button3"
       
        Button2.Location = New System.Drawing.Point(104, 8)
        Button2.Size = New System.Drawing.Size(88, 32)
        Button2.TabIndex = 2
        Button2.Text = "Button2"
        Me.Text = "Form1"
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(296, 29)
       
        Me.Controls.Add(Button3)
        Me.Controls.Add(Button2)
        Me.Controls.Add(Button1)
        Me.Controls.Add(AxMMControl1)
       
        AxMMControl1.EndInit()
    End Sub
   
#End Region
    ''''上面的代碼是對屬性的描述,是系統自已生成的,不要隨意修改
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        AxMMControl1.From = 8815 ''''從3000毫秒開始
        AxMMControl1.To =15624 ''''從6000毫秒結束
        AxMMControl1.Command = "play" ''''播放
    End Sub
    
    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.Dispose() ''''調用dispose退出程序,釋放佔用的資源
    End Sub
    
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        AxMMControl1.From = 0 ''''從 0毫秒開始
        AxMMControl1.To = 8815 ''''從3000毫秒結束
        AxMMControl1.Command = "play" ''''播放
    End Sub
   
    Public Sub me_load()
        Me.BackColor = color.BlanchedAlmond ''''改變背景色爲BlanchedAlmond
        Me.BorderStyle = FormBorderStyle.None ''''改變窗體邊框爲none,沒有標題欄
        button1.Text = "播放上段" : button2.Text = "播放下段" : button3.Text = "退出程序"
        AxMMControl1.TimeFormat = 0
        AxMMControl1.DeviceType = "waveaudio" ''''定義播放*.wav格式
        AxMMControl1.filename = System.WinForms.Application.StartUpPath & "/" & "muli.wav" ''''載入文件, System.WinForms.Application.StartUpPath爲當前目錄的意思
        AxMMControl1.Command = "open" ''''打開載入的文件
        AxMMControl1.Visible = False ''''使控件不可見,在後臺工作
    End Sub
End Class
        至於從幾毫秒開始到幾毫秒結束,是把不同的聲音文件使用如acoustica.exe這樣的聲音編輯程序整理成一個文件,記住先使用windows的錄音機錄下來,這樣生成的文件較小,把一些雜音,空白都剪切掉,這樣就是很小了
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章