Quenta221
Quenta221

Reputation: 21

Why escape sequence "\a" doesn't produce sound in Windows Form application?

I'm using visual studio and I've created a windows form application for C#. I tried the codes:

//1st
textBox1.Text = "\a";
Thread.Sleep(500);

and

//2nd
Messagebox.Show("\a");
Thread.Sleep(500);

and

//3rd
Console.WriteLine("\a");
Thread.Sleep(500);

but none of these codes produced any sounds from the \a escape sequence. However, when I tried the 3rd set of codes on a Console application instead, it worked. What codes should I use to allow the \a escape sequence to work and produce a sound on windows form application?

Upvotes: 1

Views: 308

Answers (1)

René Vogt
René Vogt

Reputation: 43876

I think \a is only interpreted as beep by the console window. To play a beep sound in a windows forms application you can use:

SystemSounds.Beep.Play();

See this Microsoft article.

Upvotes: 7

Related Questions