begin process at 2008 07 18 20:08:38
1 212 565 membres
418 nouveaux aujourd'hui
14 164 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

AUDIOBUTTON


Information sur la source

Catégorie :Control Source .NET ( DotNet ) Niveau : Débutant Date de création : 19/08/2003 Date de mise à jour : 19/08/2003 10:57:19 Vu / téléchargé: 4 783 / 273

Note :
7 / 10 - par 1 personne
7,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

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
 
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

    Aucun commentaire pour le moment.

Ajouter un commentaire

Pub



Appels d'offres

Dessins techniques
Budget : 60€
Animation Flash - Doma...
Budget : 370€
Application flash medi...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Boutique

Boutique de goodies CodeS-SourceS