Accueil > > > AUDIOBUTTON
AUDIOBUTTON
Information sur la source
Description
C'est un contrôle qui hérite de la classe ButtonBase. Je lui ai rajouté la possibilité de jouer un fichier wav sur les événements de la souris : Enter, Leave, Click, MouseUp, MouseDown
Source
- Imports System.Drawing.Drawing2D
- Public Class AudioBtn
- Inherits System.Windows.Forms.Button
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
- 'We add the different handlers
- AddHandler Me.MouseEnter, AddressOf PlayMouseEnterSound
- AddHandler Me.MouseLeave, AddressOf PlayMouseLeaveSound
- AddHandler Me.Click, AddressOf PlayMouseClickSound
- AddHandler Me.MouseDown, AddressOf PlayMouseDownSound
- AddHandler Me.MouseUp, AddressOf PlayMouseUpSound
-
- End Sub
-
- 'UserControl1 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 btnMain As System.Windows.Forms.Button
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.SuspendLayout()
- '
- 'AudioBtn
- '
- Me.Name = "AudioBtn"
- Me.Size = New System.Drawing.Size(296, 120)
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
- Private mEnterWaveFile As String
- Private mLeaveWaveFile As String
- Private mClickWaveFile As String
- Private mDownWaveFile As String
- Private mUpWaveFile As String
- Private mSndPlayer As New SoundPlayer
-
- Public Property MouseEnterWaveFile() As String
- Get
- Return mEnterWaveFile
- End Get
- Set(ByVal Value As String)
- If System.IO.File.Exists(Value) = True Then
- mEnterWaveFile = Value.Trim
- End If
- End Set
- End Property
-
- Public Property MouseLeaveWaveFile() As String
- Get
- Return mLeaveWaveFile
- End Get
- Set(ByVal Value As String)
- If System.IO.File.Exists(Value) = True Then
- mLeaveWaveFile = Value.Trim
- End If
- End Set
- End Property
-
- Public Property MouseClickWaveFile() As String
- Get
- Return mClickWaveFile
- End Get
- Set(ByVal Value As String)
- If System.IO.File.Exists(Value) = True Then
- mClickWaveFile = Value.Trim
- End If
- End Set
- End Property
-
- Public Property MouseDownWaveFile() As String
- Get
- Return mDownWaveFile
- End Get
- Set(ByVal Value As String)
- If System.IO.File.Exists(Value) = True Then
- mDownWaveFile = Value.Trim
- End If
- End Set
- End Property
-
- Public Property MouseUpWaveFile() As String
- Get
- Return mUpWaveFile
- End Get
- Set(ByVal Value As String)
- If System.IO.File.Exists(Value) = True Then
- mUpWaveFile = Value.Trim
- End If
- End Set
- End Property
-
- Private Sub PlayMouseEnterSound(ByVal Sender As Object, ByVal e As EventArgs)
- If mEnterWaveFile <> "" Then
- Try
- mSndPlayer.Play(mEnterWaveFile)
- Catch PlayErr As Exception
- 'We do nothing
- End Try
- #If DEBUG Then
- Debug.Write("Enter")
- #End If
- End If
- End Sub
-
- Private Sub PlayMouseLeaveSound(ByVal Sender As Object, ByVal e As EventArgs)
- If mLeaveWaveFile <> "" Then
- Try
- mSndPlayer.Play(MouseLeaveWaveFile)
- Catch PlayErr As Exception
- 'We do nothing
- End Try
- #If DEBUG Then
- Debug.Write("Leave")
- #End If
- End If
- End Sub
-
- Private Sub PlayMouseClickSound(ByVal Sender As Object, ByVal e As EventArgs)
- If mClickWaveFile <> "" Then
- Try
- mSndPlayer.Play(mClickWaveFile)
- Catch PlayErr As Exception
- 'We do nothing
- End Try
- #If DEBUG Then
- Debug.Write("Click")
- #End If
- End If
- End Sub
-
- Private Sub PlayMouseDownSound(ByVal Sender As Object, ByVal e As MouseEventArgs)
- If mClickWaveFile <> "" Then
- Try
- mSndPlayer.Play(mDownWaveFile)
- Catch PlayErr As Exception
- 'We do nothing
- End Try
- #If DEBUG Then
- Debug.Write("Down")
- #End If
- End If
- End Sub
-
- Private Sub PlayMouseUpSound(ByVal Sender As Object, ByVal e As MouseEventArgs)
- If mClickWaveFile <> "" Then
- Try
- mSndPlayer.Play(mUpWaveFile)
- Catch PlayErr As Exception
- 'We do nothing
- End Try
- #If DEBUG Then
- Debug.Write("Up")
- #End If
- End If
- End Sub
-
- Private Class SoundPlayer
- Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
- ' name specifies the sound file when the SND_FILENAME flag is set.
- ' hmod specifies an executable file handle.
- ' hmod must be Nothing if the SND_RESOURCE flag is not set.
- ' flags specifies which flags are set.
-
- ' The PlaySound documentation lists all valid flags.
- Private Enum SndModeEnum
- SND_SYNC = &H0
- SND_ASYNC = &H1
- SND_FILENAME = &H20000
- SND_RESOURCE = &H40004
- End Enum
-
- Private Const SND_SYNC As Integer = &H0 ' play synchronously
- Private Const SND_ASYNC As Integer = &H1 ' play asynchronously
- Private Const SND_FILENAME As Integer = &H20000 ' name is file name
- Private Const SND_RESOURCE As Integer = &H40004 ' name is resource name or atom
-
- Public Sub Play(ByVal filename As String)
- ' Plays a sound from filename.
- PlaySound(filename, Nothing, SndModeEnum.SND_FILENAME Or SndModeEnum.SND_ASYNC)
- End Sub
- End Class
-
- Protected Overrides Sub Finalize()
- RemoveHandler Me.MouseEnter, AddressOf PlayMouseEnterSound
- RemoveHandler Me.MouseLeave, AddressOf PlayMouseLeaveSound
- RemoveHandler Me.Click, AddressOf PlayMouseClickSound
- RemoveHandler Me.MouseDown, AddressOf PlayMouseDownSound
- RemoveHandler Me.MouseUp, AddressOf PlayMouseUpSound
-
- MyBase.Finalize()
- End Sub
-
- End Class
-
Imports System.Drawing.Drawing2D
Public Class AudioBtn
Inherits System.Windows.Forms.Button
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'We add the different handlers
AddHandler Me.MouseEnter, AddressOf PlayMouseEnterSound
AddHandler Me.MouseLeave, AddressOf PlayMouseLeaveSound
AddHandler Me.Click, AddressOf PlayMouseClickSound
AddHandler Me.MouseDown, AddressOf PlayMouseDownSound
AddHandler Me.MouseUp, AddressOf PlayMouseUpSound
End Sub
'UserControl1 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 btnMain As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SuspendLayout()
'
'AudioBtn
'
Me.Name = "AudioBtn"
Me.Size = New System.Drawing.Size(296, 120)
Me.ResumeLayout(False)
End Sub
#End Region
Private mEnterWaveFile As String
Private mLeaveWaveFile As String
Private mClickWaveFile As String
Private mDownWaveFile As String
Private mUpWaveFile As String
Private mSndPlayer As New SoundPlayer
Public Property MouseEnterWaveFile() As String
Get
Return mEnterWaveFile
End Get
Set(ByVal Value As String)
If System.IO.File.Exists(Value) = True Then
mEnterWaveFile = Value.Trim
End If
End Set
End Property
Public Property MouseLeaveWaveFile() As String
Get
Return mLeaveWaveFile
End Get
Set(ByVal Value As String)
If System.IO.File.Exists(Value) = True Then
mLeaveWaveFile = Value.Trim
End If
End Set
End Property
Public Property MouseClickWaveFile() As String
Get
Return mClickWaveFile
End Get
Set(ByVal Value As String)
If System.IO.File.Exists(Value) = True Then
mClickWaveFile = Value.Trim
End If
End Set
End Property
Public Property MouseDownWaveFile() As String
Get
Return mDownWaveFile
End Get
Set(ByVal Value As String)
If System.IO.File.Exists(Value) = True Then
mDownWaveFile = Value.Trim
End If
End Set
End Property
Public Property MouseUpWaveFile() As String
Get
Return mUpWaveFile
End Get
Set(ByVal Value As String)
If System.IO.File.Exists(Value) = True Then
mUpWaveFile = Value.Trim
End If
End Set
End Property
Private Sub PlayMouseEnterSound(ByVal Sender As Object, ByVal e As EventArgs)
If mEnterWaveFile <> "" Then
Try
mSndPlayer.Play(mEnterWaveFile)
Catch PlayErr As Exception
'We do nothing
End Try
#If DEBUG Then
Debug.Write("Enter")
#End If
End If
End Sub
Private Sub PlayMouseLeaveSound(ByVal Sender As Object, ByVal e As EventArgs)
If mLeaveWaveFile <> "" Then
Try
mSndPlayer.Play(MouseLeaveWaveFile)
Catch PlayErr As Exception
'We do nothing
End Try
#If DEBUG Then
Debug.Write("Leave")
#End If
End If
End Sub
Private Sub PlayMouseClickSound(ByVal Sender As Object, ByVal e As EventArgs)
If mClickWaveFile <> "" Then
Try
mSndPlayer.Play(mClickWaveFile)
Catch PlayErr As Exception
'We do nothing
End Try
#If DEBUG Then
Debug.Write("Click")
#End If
End If
End Sub
Private Sub PlayMouseDownSound(ByVal Sender As Object, ByVal e As MouseEventArgs)
If mClickWaveFile <> "" Then
Try
mSndPlayer.Play(mDownWaveFile)
Catch PlayErr As Exception
'We do nothing
End Try
#If DEBUG Then
Debug.Write("Down")
#End If
End If
End Sub
Private Sub PlayMouseUpSound(ByVal Sender As Object, ByVal e As MouseEventArgs)
If mClickWaveFile <> "" Then
Try
mSndPlayer.Play(mUpWaveFile)
Catch PlayErr As Exception
'We do nothing
End Try
#If DEBUG Then
Debug.Write("Up")
#End If
End If
End Sub
Private Class SoundPlayer
Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
' name specifies the sound file when the SND_FILENAME flag is set.
' hmod specifies an executable file handle.
' hmod must be Nothing if the SND_RESOURCE flag is not set.
' flags specifies which flags are set.
' The PlaySound documentation lists all valid flags.
Private Enum SndModeEnum
SND_SYNC = &H0
SND_ASYNC = &H1
SND_FILENAME = &H20000
SND_RESOURCE = &H40004
End Enum
Private Const SND_SYNC As Integer = &H0 ' play synchronously
Private Const SND_ASYNC As Integer = &H1 ' play asynchronously
Private Const SND_FILENAME As Integer = &H20000 ' name is file name
Private Const SND_RESOURCE As Integer = &H40004 ' name is resource name or atom
Public Sub Play(ByVal filename As String)
' Plays a sound from filename.
PlaySound(filename, Nothing, SndModeEnum.SND_FILENAME Or SndModeEnum.SND_ASYNC)
End Sub
End Class
Protected Overrides Sub Finalize()
RemoveHandler Me.MouseEnter, AddressOf PlayMouseEnterSound
RemoveHandler Me.MouseLeave, AddressOf PlayMouseLeaveSound
RemoveHandler Me.Click, AddressOf PlayMouseClickSound
RemoveHandler Me.MouseDown, AddressOf PlayMouseDownSound
RemoveHandler Me.MouseUp, AddressOf PlayMouseUpSound
MyBase.Finalize()
End Sub
End Class
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOURTECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOUR par ROMELARD Fabrice
Après un retour sur l'histoire des TechDays de Paris et le fait que ce soit le plus gros event MS au monde (du fait de sa gratuité), le président de MS France (Eric Boustoullier) a fait une présentation de la vision Microsoft pour les années à venir...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
Comparez les prix

HTC Magic
Entre 429€ et 429€
|