I am certain this is simple, but I am not used to working with forms. I have a very simple app that I want to have load a form containing a button, and then I want to call a method that will play a sound. My question is where do I call the method? -
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
PlaySound();
-
}
-
This code plays the sound, but does not bring up the form.
8 12916
Nvm. Highlighted the form in VS, selected the action button, and then selected the method I wanted to run for Load.
I spoke too soon. The sound now plays, but the form never appears on the screen. Considering I am just trying to have the simple form with one button appear, and have the sound play until the button on the form is selected, what do I need to do here?
In your designer window, double click on the form's title bar. This will auto generate an event handler method for the Load event. Put your code there.
@insertAlias
I should clarify. I understand how to generate an event handler for the Load event, but while the Load event executes, the form never actually appears. So I hear the sound repeating, but I do not see the form.
So it doesn't work in the Load event either? I thought the problem might be because you called the method in the constructor, not the Load handler.
Let me think about this and I'll get back to you.
-
-
namespace EmailAlert
-
{
-
public partial class EmailAlert : Form
-
{
-
public EmailAlert()
-
{
-
InitializeComponent();
-
}
-
private void button1_Click(object sender, EventArgs e)
-
{
-
Application.Exit();
-
}
-
private void EmailAlert_Load(object sender, EventArgs e)
-
{
-
int i = 0;
-
while (i < 200)
-
{
-
SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
-
simpleSound.Play();
-
Thread.Sleep(5000);
-
i++;
-
}
-
}
-
}
-
}
-
With this line added to InitializeComponent: -
-
this.Load += new System.EventHandler(this.EmailAlert_Load);
-
Well, you might want to start a new thread and play the sound there rather than the GUI thread.
Plater 7,872
Recognized Expert Expert
Yes the sound should be played in a seperate thread (actually I thought generally the sound interop was non blocking and you made like mms calls or whatever)
Anyway, you should also have an Application.DoEvents() inside that for loop to keep it from being a "busy loop". Although the thread.sleep will release CPU time, it doesn't allow the form to processes windows messages.
If your sound is short enough, adding that Application.DoEvents() might be enough to solve your problem
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: JoeK |
last post by:
Hey all,
I am automating a web page from Visual Foxpro. I can control all the
textboxes, radio buttons, and command buttons using syntax such as:
...
|
by: David N |
last post by:
Hi All,
I just wonder if in C#, I can develop a user defined control that can call
its parent function which is not yet developed. For example, how do I make
my user control call a...
|
by: John |
last post by:
Hi all,
This really is quite an urgent matter.
I have a page with multiple, dynamically-loaded user controls and when a
user clicks on a button, the whole form is submitted. Now at this stage...
|
by: keith.walter |
last post by:
My first asp.net app is almost "done" and I am stuck. Here is my
situation: I have a "mother" page add_customer.aspx and a"child" user
control add_group.ascx. On the mother page is an "add...
|
by: Partha Protim Roy |
last post by:
Hello,
I have a Customer form say A to enter/update customer details. In the Form
A I have a button which opens another form say B.
In the Form B, I am providing user with a option to search...
| |
by: Steve_Black |
last post by:
Hello,
I'm toying with the idea of loading a MenuStrip (VB.Net 2005)
dynamically based on who is logged into my system. Every user has
different security settings and I want to customize the...
|
by: roland.bali |
last post by:
Hi,
Here is the basic setup, my base class is Shoe which has a child class
called Sandal. I would like to create objects by calling Sandal.Load.
But without overloading Load in Sandal and...
|
by: tcomer |
last post by:
Hello,
I'm working on an application that grabs some data from the web via
HttpWebRequest. I'm using a local objects method to get the data, but
the problem is that my form doesn't load until...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |