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
[SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko [FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|