473,657 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call Method On Form Load

233 New Member
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?

Expand|Select|Wrap|Line Numbers
  1.  
  2. public partial class Form1 : Form
  3. {
  4. public Form1()
  5. {
  6. InitializeComponent();
  7. PlaySound();
  8. }
  9.  
This code plays the sound, but does not bring up the form.
Jan 15 '09 #1
8 12934
mcfly1204
233 New Member
Nvm. Highlighted the form in VS, selected the action button, and then selected the method I wanted to run for Load.
Jan 15 '09 #2
mcfly1204
233 New Member
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?
Jan 16 '09 #3
Curtis Rutland
3,256 Recognized Expert Specialist
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.
Jan 16 '09 #4
mcfly1204
233 New Member
@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.
Jan 16 '09 #5
Curtis Rutland
3,256 Recognized Expert Specialist
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.
Jan 16 '09 #6
mcfly1204
233 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2. namespace EmailAlert
  3. {
  4. public partial class EmailAlert : Form
  5. {
  6. public EmailAlert()
  7. {
  8. InitializeComponent();
  9. }
  10. private void button1_Click(object sender, EventArgs e)
  11. {
  12. Application.Exit();
  13. }
  14. private void EmailAlert_Load(object sender, EventArgs e)
  15. {
  16. int i = 0;
  17. while (i < 200)
  18. {
  19. SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
  20. simpleSound.Play();
  21. Thread.Sleep(5000);
  22. i++;
  23. }
  24. }
  25. }
  26. }
  27.  
With this line added to InitializeCompo nent:

Expand|Select|Wrap|Line Numbers
  1.  
  2. this.Load += new System.EventHandler(this.EmailAlert_Load);
  3.  
Jan 16 '09 #7
Curtis Rutland
3,256 Recognized Expert Specialist
Well, you might want to start a new thread and play the sound there rather than the GUI thread.
Jan 16 '09 #8
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
Jan 16 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4034
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
3
11873
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
4
4279
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':
1
2632
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...
33
1857
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.
7
10056
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
6
3617
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 ?????
5
1695
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;
0
8323
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,...
0
8739
jinu1996
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...
1
8513
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,...
1
6176
isladogs
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...
0
4173
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...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.