Create a Windows Application
1. Start Microsoft Visual Studio .NET or Microsoft Visual Basic 2005.
2. On the File menu, point to New, and then click Project.
3. Under Project Types, click Visual Basic Projects.
Note In Visual Studio 2005, click Visual Basic under Project Types.
4. Under Templates, click Windows Application.
5. In the Name box, type AudioDemo, and then click OK. By default, Form1.vb is created.
Back to the top
Add a Windows Media Player control to the Application
1. Start Visual Studio .NET or Visual Studio 2005.
2. On the Tools menu, click Add/Remove Toolbox Items.
Note In Visual Studio .NET 2002, on the Tools menu, click Customize Toolbox.
In Visual Studio 2005, click Choose Toolbox Items on the Tools menu.
3. Click the COM Components tab, and then click Browse.
4. Locate and then click Msdxm.ocx, and then click Open.
Note Msdxm.ocx is typically located in %WINDIR%/System32, where %WINDIR% is the location of the Windows directory on your computer.
5. In the Customize Toolbox or Choose Toolbox Item dialog box, click OK. In Visual Studio .NET 2003 and in Visual Studio 2005, a WindowsMediaPlayer control is added to the toolbox. In Visual Studio .NET 2002, a MediaPlayer control is added to the toolbox.
6. In Visual Studio .NET 2003 or in Visual Studio 2005, add a WindowsMediaPlayer control to Form1. In Visual Studio .NET 2002, add a MediaPlayer control.
7. AxMediaPlayer1 is added to Form1.
Back to the top
Add Buttons to Control the Windows Media Player
1. Add four Button controls to Form1.
2. Click Button1.
3. In the Properties pane, change the Text property of Button1 to Load.
4. Click Button2.
5. In the Properties pane, change the Text property of Button2 to Play.
6. Click Button3.
7. In Properties pane, change the Text property of Button3 to Pause.
8. Click Button4.
9. In the Properties pane, change the Text property of Button4 to Stop.
Back to the top
Add an OpenFileDialog Component to Load an Audio File
Add a OpenFileDialog component to Form1.
Back to the top
Add Initialization Code
1. On the View menu, click Code.
2. In the "Windows Form Designer generated code" region, locate the following code:InitializeComponent()
3. Add the following code after the code that you located in step 2:' Disable the Play, the Pause, and the Stop buttons.
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
' Hide the Windows Media Player.
AxMediaPlayer1.Visible = False
Back to the top
Add Code to Load an Audio File
1. On the View menu, click Designer.
2. Double-click the Load control, and then add the following code to the Button1_Click event-handler:' Reset the file names for the Open File dialog box and for the Media Player.
OpenFileDialog1.FileName = ""
AxMediaPlayer1.FileName = ""
' Display the Open File dialog box.
OpenFileDialog1.ShowDialog()
' Verify that Cancel was not clicked.
If Not OpenFileDialog1.FileName = "" Then
' Disable the Load button.
Button1.Enabled = False
' Prevent the Media Player from automatically playing loaded files.
AxMediaPlayer1.AutoStart = False
' Set the Media Player audio file.
AxMediaPlayer1.FileName = OpenFileDialog1.FileName
MessageBox.Show("The following file has been loaded in the Media Player control: " + AxMediaPlayer1.FileName)
' Enable the Play button.
Button2.Enabled = True
Else
' Disable the Play button.
Button2.Enabled = False
End If
Back to the top
Add Code to Play an Audio File
1. On the View menu, click Designer.
2. Double-click the Play control, and then add the following code to the Button2_Click event-handler:' Disable the Load and the Play buttons.
Button1.Enabled = False
Button2.Enabled = False
' Play the audio file.
AxMediaPlayer1.Play()
' Enable the Pause and the Stop buttons.
Button3.Enabled = True
Button4.Enabled = True
Back to the top
Add Code to Pause an Audio File
1. On the View menu, click Designer.
2. Double-click the Pause control, and then add the following code to the Button3_Click event-handler:' Disable the Pause button.
Button3.Enabled = False
' Pause the audio file.
AxMediaPlayer1.Pause()
' Enable the Play button.
Button2.Enabled = True
Back to the top
Add Code to Stop an Audio File
1. On the View menu, click Designer.
2. Double-click the Stop control, and then add the following code to the Button4_Click event-handler:' Disable the Pause and the Stop buttons.
Button3.Enabled = False
Button4.Enabled = False
' Stop playing the audio file, and then reset the next play position to the beginning.
AxMediaPlayer1.Stop()
AxMediaPlayer1.CurrentPosition = 0
' Enable the Load and the Play buttons.
Button1.Enabled = True
Button2.Enabled = True
Back to the top
Sample Code Listing (Form1.vb)
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Disable the Play, the Pause, and the Stop buttons.
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
' Hide the Media Player.
AxMediaPlayer1.Visible = False
' Add any initialization after the InitializeComponent() call.
End Sub
' Form overrides Dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' Required by the Windows Form Designer.
Private components As System.ComponentModel.IContainer
' 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.
Friend WithEvents AxMediaPlayer1 As AxMediaPlayer.AxMediaPlayer
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.AxMediaPlayer1 = New AxMediaPlayer.AxMediaPlayer
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
CType(Me.AxMediaPlayer1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AxMediaPlayer1
'
Me.AxMediaPlayer1.Location = New System.Drawing.Point(224, 0)
Me.AxMediaPlayer1.Name = "AxMediaPlayer1"
Me.AxMediaPlayer1.OcxState = CType(resources.GetObject("AxMediaPlayer1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxMediaPlayer1.Size = New System.Drawing.Size(286, 225)
Me.AxMediaPlayer1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 72)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Load"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(32, 104)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Text = "Play"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(40, 136)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 3
Me.Button3.Text = "Pause"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(56, 192)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 4
Me.Button4.Text = "Stop"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(712, 397)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.AxMediaPlayer1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.AxMediaPlayer1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Reset the file names for the Open dialog box and for the Media Player.
OpenFileDialog1.FileName = ""
AxMediaPlayer1.FileName = ""
' Display the Open File dialog box.
OpenFileDialog1.ShowDialog()
' Verify that Cancel was not clicked.
If Not OpenFileDialog1.FileName = "" Then
' Disable the Load button.
Button1.Enabled = False
' Prevent the Media Player from automatically playing loaded files.
AxMediaPlayer1.AutoStart = False
' Set the Media Player audio file.
AxMediaPlayer1.FileName = OpenFileDialog1.FileName
MessageBox.Show("The following file has been loaded in the Media Player control: " + AxMediaPlayer1.FileName)
' Enable the Play button.
Button2.Enabled = True
Else
' Disable the Play button.
Button2.Enabled = False
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Disable the Load and the Play buttons.
Button1.Enabled = False
Button2.Enabled = False
' Play the audio file.
AxMediaPlayer1.Play()
' Enable the Pause and the Stop buttons.
Button3.Enabled = True
Button4.Enabled = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' Disable the Pause button.
Button3.Enabled = False
' Pause the audio file.
AxMediaPlayer1.Pause()
' Enable the Play button.
Button2.Enabled = True
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
' Disable the Pause and the Stop buttons.
Button3.Enabled = False
Button4.Enabled = False
' Stop playing the audio file, and then reset the next play position to the beginning.
AxMediaPlayer1.Stop()
AxMediaPlayer1.CurrentPosition = 0
' Enable the Load and the Play buttons.
Button1.Enabled = True
Button2.Enabled = True
End Sub
End Class
source :http://msdn2.microsoft.com
-------------------------------------------------------
Trik Gambar Bergerak
Trik Gambar-dimouse
Trik hapus pwd mysql
Trik insertin to db
Trik jadi root dilinux
Trik jam-distatus-bar
Trik Koneksi-ke database
Trik Koneksi-msql-php
Trik lihat-database-mysql
Trik membahas-fungsi-else
Trik member-area
Using Session
Using Thread pool sql2005
Using check box vb2008
Using radio button vb2008
Valentineday
vb2008 with control
vb2008 with control properties
vb2008 with oriented programming
VB.NET Solution files
VB.NET Code myclass