Search VB 2010

Thursday, October 18, 2012

Visual Basic 2010 - Button Sound / Music Play

Visual Basic 2010 - Button Sound

Visual Basic 2010 - Play sound on buttons
Visual Basic 2010 - Play sound on buttons

The code is simply goes like this

You can copy and paste in your (Click_Event) or whatever it is you wish (MouseClick - MouseHover - MouseLeave) :


  1. Dim MySound As New System.Media.SoundPlayer()  
  2.  
  3. MySound.SoundLocation = "path to the .Wav file"
  4. MySound.Load()
  5. MySound.Play()
  6. ' OR you can use this :
  7. Sub PlaySystemSound()
  8. My.Computer.Audio.PlaySystemSound(
    System.Media.SystemSounds.Asterisk)
     
  9. End Sub

Background playing 

It lets the application execute other code while the sound plays. The My.Computer.Audio.Play method allows the application to play only one background sound at a time; when the application plays a new background sound, it stops playing the previous background sound. You can also play a sound and wait for it to complete.

For Visual Basic 2010 and in general, when an application plays a looping sound, it should eventually stop the sound. For more information, see How to: Stop Playing Sounds in the Background in Visual Basic 2010.

Example

The My.Computer.Audio.Play method plays a sound. When AudioPlayMode.WaitToComplete is specified, My.Computer.Audio.Play waits until the sound completes before calling code continues.

Check that the file name references a .wav sound file on your system.
  1. Sub PlayBackgroundSoundFile()

    My.Computer.Audio.Play("C:\Waterfall.wav",
    AudioPlayMode.WaitToComplete)

    End Sub
The My.Computer.Audio.Play method plays a sound. When AudioPlayMode.WaitToComplete is specified, My.Computer.Audio.Play waits until the sound completes before calling code continues.
Check that the application resources include a .wav sound file named Waterfall.
  1. Sub PlayBackgroundSoundResource()

    My.Computer.Audio.Play(My.Resources.Waterfall,
    AudioPlayMode.WaitToComplete)

    End Sub


Here are some online Visual Basic lessons and courses :

Thursday, October 11, 2012

Visual Basic Online Course ProgressBar

Visual Basic 2010 ProgressBar Control 

VB2010 Progress bar - Visual Basic Online Course

 Using the ProgressBar control Example :

- Create New Windows Project
- Button1
- ProgressBar1
- Logic : We will generate 4 MessageBoxes by clicking the Button1 Control and everytime a messagebox shows up, a ProgressBar step will be taken.

Progress Bar Class : In .Net Framework4.0

A ProgressBar control consists of a window that is filled, by default from left to right, as an operation progresses. The control has a range and a current position.
ProgressBar overrides the metadata of the Maximum property and sets its default to 100. ProgressBar overrides the metadata of the Focusable property and sets its default to false. For more information, see Dependency Properties Overview.

Customizing the ProgressBar Control

To apply the same property settings to multiple ProgressBar controls, use the Style property. You can modify the default ControlTemplate to give the control a unique appearance. For more information about creating a ControlTemplate, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. To see the parts and states that are specific to the ProgressBar, see ProgressBar Styles and Templates.
Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Default WPF Themes.

NoteNote
Setting a visual property will only have an effect if that property is both present in ProgressBar control's default template and is set by using a TemplateBinding. You can find a list of visual properties in the "Changing the Visual Structure of a Control" section in Customizing the Appearance of an Existing Control by Creating a Control Template.

How to call a Progress Bar from a Module in VB 2010

In addition to our example about Progress Bar, what if we wanted to code the progress bar to call it from another level [Module Level] !

Create Visual Basic 2010 Windows Form Application
Place a Progressbar (Progressbar1) control on the Form (Form1
Add new Module (Module1)

Code :

Now, run your application and click on any part of the Form1, you will notice that the ProgressBar is working.

Visual Basic Courses - Share