begin process at 2010 02 09 21:02:50
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Control

 > AUDIOBUTTON

AUDIOBUTTON


 Information sur la source

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

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
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é :5 650 / 299

Auteur : RayBan

Ecrire un message privé
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
 


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source .NET (Dotnet) LOGTOFILE
Source .NET (Dotnet) CRYPTAGE / DECRYPTAGE RC4 POUR VB .NET

 Sources de la même categorie

Source avec une capture Source .NET (Dotnet) CREATION DE CONTROLS DYNAMIQUE + DEPLACEMENT ET REDIMENTION ... par tresorsdevie
Source avec Zip Source avec une capture USERCONTROL AVEC PROPERTIES PERSONALISABLE par Polack77
Source avec Zip Source avec une capture BOUTON UP_DOWN par epson1
Source avec Zip Source avec une capture CONTROLS ++(CONTROLS GRAPHIQUES EN CONSTRUCTION) par Flocreate
Source avec Zip Source .NET (Dotnet) CRÉER UN VRAI OCX EN DOTNET par Patrice99

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix


HTC Magic

Entre 429€ et 429€

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,452 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales