Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows Beep

Posted on 2009-05-08
11
Medium Priority
?
566 Views
Last Modified: 2013-12-17
I have read plenty of posts about people trying to stop the windows beep that occurs when you hit the enter key in a textbox that does not accept multiple lines, but I am trying to duplicate that tone.  Can anyone tell me how to duplicate the tone you get in a textbox when hitting the enter key????
0
Comment
Question by:gvector1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 2
11 Comments
 
LVL 6

Expert Comment

by:Cebik
ID: 24340812
I'm searshing now how beep the same tone.

private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
        Console.Beep();
}

Open in new window

0
 
LVL 6

Expert Comment

by:Cebik
ID: 24340856
0
 

Author Comment

by:gvector1
ID: 24340868
I am not doing this within another method.  I have tried console.beep and it appears to use the internals of the pc to generate a tone as opposed to the windows tone generated through the speakers within the textbox.  I am wanting to duplicate the same sound.  What I have is a datagrid cell I am restricting text length.  If the text has reached maximum size, I want to generate that tone.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Expert Comment

by:Cebik
ID: 24340870
done :)

[DllImport("winmm.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
static extern bool PlaySound(string pszSound, IntPtr hMod, SoundFlags sf);
 
[Flags]
public enum SoundFlags : int
{
    SND_SYNC = 0x0000,  // play synchronously (default)
    SND_ASYNC = 0x0001,  // play asynchronously
    SND_NODEFAULT = 0x0002,  // silence (!default) if sound not found
    SND_MEMORY = 0x0004,  // pszSound points to a memory file
    SND_LOOP = 0x0008,  // loop the sound until next sndPlaySound
    SND_NOSTOP = 0x0010,  // don't stop any currently playing sound
    SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
    SND_ALIAS = 0x00010000, // name is a registry alias
    SND_ALIAS_ID = 0x00110000, // alias is a predefined ID
    SND_FILENAME = 0x00020000, // name is file name
    SND_RESOURCE = 0x00040004  // name is resource name or atom
}
 
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
            PlaySound("SND_ALIAS_SYSTEMDEFAULT", IntPtr.Zero, SoundFlags.SND_ALIAS);
}

Open in new window

0
 
LVL 6

Expert Comment

by:Cebik
ID: 24340873
0
 
LVL 3

Accepted Solution

by:
SalmanZG earned 2000 total points
ID: 24340926
0
 
LVL 6

Expert Comment

by:Cebik
ID: 24340964
@SalmanZG:
wow :)
great
but there is no double sounds



private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
        SystemSounds.Beep.Play();
        //PlaySound("SND_ALIAS_SYSTEMDEFAULT", IntPtr.Zero, SoundFlags.SND_ALIAS);
}

Open in new window

0
 
LVL 6

Expert Comment

by:Cebik
ID: 24340981
now is

private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        SystemSounds.Beep.Play();
        Thread.Sleep(300);
        SystemSounds.Beep.Play();
    }
}

Open in new window

0
 
LVL 6

Expert Comment

by:Cebik
ID: 24340997

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        SystemSounds.Beep.Play();
        Thread.Sleep(150);
        SystemSounds.Beep.Play();
        e.SuppressKeyPress = true;
    }
}

Open in new window

0
 
LVL 6

Expert Comment

by:Cebik
ID: 24341002
@SalmanZG:

thank's for this !!!
:)
0
 

Author Closing Comment

by:gvector1
ID: 31579668
That is exactly what I was looking for.....Thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question