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 12934
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 InitializeCompo nent: -
-
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.DoE vents() 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.DoE vents() 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:
oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue>
But I cannot control a dropdown with an onchange event. I can set the
dropdown's value and selectedIndex, but then calling the onChange() or
Click() does not do anything. It only seems to fire the onchange if I
|
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 to-be-developed-function cmdOkay_Click() function as
described below.
1. Create an user control that contains an OK button as below
Public Class MyButton:System.Windows.Form.UserControl
|
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 I
know I need to call a function that will save data but I'm not sure exactly
when to call this function.
I've tried two ways and both seem to have 'gotcha's':
|
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 group" button
that makes the the panel inwhich the add_customer control resides
VISIBLE=True. On the control, the user can edit the list of groups, or
add a new one. After the edit is complete I want to make the panel
again VISIBLE=False, as well as...
|
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 Customer from the
database depending on various search criteria.
On matching the criteria, list of Customer is displayed in the datagrid.
| |
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 main menu
instead of showing all possible options and only enabling/disabling
certain ones.
I have a table that stores the menu item name, parent item (if
applicable), display order, etc. so that I can dynamically load my
|
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 sending the Sandal type to
the base class I can not instantiate a Sandal class from within Shoe.
Public Class Shoe
Public Shared Function Load() As Object
return ?????
|
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 this method has
finished what it's doing.. which takes about 10-15 seconds. Here is
what I have:
Using System.Threading;
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |