走近VB.Net(十) 播放声音文件

来源:互联网 发布:php给定一个字符串: 编辑:程序博客网 时间:2024/05/01 11:22
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

 

         因为考虑到有部分初学者VB6没有用过,所以我在源码中对每一句代码都进行了注释。

           首先如下添加控件:
         

          添加三个button控件,写代码如下:

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 Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

       

    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

   

    Protected Sub AxMMControl1_OLEDragDrop(ByVal sender As Object, ByVal e As AxMCI.DmciEvents_OLEDragDropEvent)

       

    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







中客科技信息有限公司信息监控系统提醒您:很抱歉,由于您提交的内容中或访问的内容中含有系统不允许的关键词或者您的IP受到了访问限制,本次操作无效,系统已记录您的IP及您提交的所有数据。请注意,不要提交任何违反国家规定的内容!本次拦截的相关信息为:不同的声音>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击