News
  • Favorite
  • Facebook
  • Twitter
  • LinkedIn

Microsoft Press Pearson Education (InformIT)
Skip Navigation Links
Pearson Education (InformIT)
Displaying an alert window in your windows forms application using C#

Some developers that use Microsoft live Messenger see an alert window when somebody of their contacts comes online. While developing BIMSI OMS applications some customers asked me to display alert messages when an order added to them and require the user to take an action.

When I saw the alert window of the Windows Live Messenger, I have decided to make BIMSI OMS alert as the one of Live Messenger.

Creating an alert window as the one of Live Messenger:

1.       Create a new windows application using Visual Studio 2005/2008 or use any windows application you have created.

2.       Add a new Windows Forms in the newly created project and name it AlertForm.

3.       In the constructor of the AlertForm add the following code to display the AlertForm in the location above the Taskbar clock section.

Rectangle screenRectangle = Screen.PrimaryScreen.WorkingArea;

this.Location = new Point(screenRectangle.Width - this.Width - 10,

    screenRectangle.Height - this.Height - 10); 

4.        The above code simply gets the working area of the client primary monitor screen and set the location of the Alert Form to the location computed above.

5.       You can also add a label control to display a message to the user.

6.       You can also add sound to the Alert Form as follows:

a.       Import the System.Media name space in the alert form. Using the following statement  using System.Media;

b.      Declare a new SoundPlayer soundPlayer object.

c.       Pass the file path of the .wav sound file to the constructor of the soundPlayer object as follow soundPlayer = new SoundPlayer(“.wav sound file path”);

d.      The file passed to soundPlayer object must be a .wav file. If you pass a .mp3 or other audio files it will throw an exception.

e.      After that call the Play method of the soundPlayer object as follows:

soundPlayer.Play();

f.        In the form closing call the Stop method of the soundPlayer object as follows:

soundPlayer.Stop();

7.       If you want to make the alert window closes after a period of time:

a.       Add the System.Timers.Timer component to the AlertForm and name it CloseTimer.

b.      Set its interval to the period you want the form to close after for example set it to 3000 milliseconds (3 seconds).

c.       Implement the Timer Elapsed event and add the following code in that event 

private void CloseTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

{

    this.Close();

}

d.      Now after the timer period is elapsed the AlertForm will close.

8.       If you want to display the Alert Window in another thread other than the main one you can use the powerfull BackgroundWorker Component that execute tasks in a Background thread with the following steps:

a.       Add the BackgroundWorker Component from the Toolbox and name it NotifyBackgroundWorker.

b.      Implement The NotifyBackgroundWorker  DoWork Event and write the code that will show the AlertForm as follows:

AlertForm alertForm = new AlertForm();

      alertForm.Show();

9.       To display the Alert window to the user you will need to follow these steps:

a.       Write the following code in the event or methods in which  you need to notify users:

if (!NotifyBackgroundWorker.IsBusy)

         {

            NotifyBackgroundWorker.RunWorkerAsync();

         }

b.      In the above code we check if the NotifyBackgroundWorker is not doing any work  and then we call the RunWorkerAsync() method that executes the code written in the DoWork Event of the NotifyBackgroundWorker.

With these steps you have created an alter window that like the one of the Windows Live Messenger

 

(88) Comments

Blog Message http://brocktonmassachusedbz.tek-blogs.com/a-vase-filled-with-evergreen-clippings-is-a-handy-buffets-media-cabinets-secretaries-and-so-forth

Im grateful for the article post. Much obliged.


Blog Message https://bit.ly/2xNUTdC

Im thankful for the article.Really thank you! Much obliged.


Blog Message https://softfay.com/audio-editing/audacity-audio-editor/

I?аАТ’аЂа†ll right away snatch your rss as I can at to find your email subscription link or newsletter service. Do you have any? Kindly let me understand in order that I may just subscribe. Thanks.


Blog Message http://www.ahmetoguzgumus.com/

Real clean web site, appreciate it for this post.


Blog Message https://www.nosh121.com/44-off-proflowers-com-completly-free-shipping-coupon-codes

you made blogging look easy. The overall look of your website is


Blog Message http://irwin1670ea.tutorial-blog.net/it-suggests-that-overall-the-spillover-effects-of-a-shared-supplier-can-explain-14-of-the-product-nature-only-and-does-not-take-into-account-your-personal-objectives-situation-or-needs

You made some respectable points there. I looked on the internet for the issue and found most people will go along with with your website.


Blog Message https://www.opalivf.com/

Very nice article and straight to the point. I am not sure if this is in fact the best place to ask but do you folks have any ideea where to get some professional writers? Thx


Blog Message http://houstonpride.org/__media__/js/netsoltrademark.php?d=blingee.com%2Fprofile%2Fyearmilk8

Muchos Gracias for your blog.Much thanks again.


Blog Message https://www.anobii.com/groups/018fe851d29f4b07fa

Thanks so much for the post.Thanks Again. Keep writing.


Blog Message https://bookmarkspot.win/story.php?title=dev-402-mock-test#discuss

Wow, great article post.Thanks Again. Fantastic.


Blog Message http://www.fmnokia.net/user/TactDrierie181/

I value the article.Really thank you! Keep writing.


Blog Message http://badgerjumbo66.nation2.com/togaf-9-part-1-exam3

Wow! Thank you! I constantly wanted to write on my website something like that. Can I take a portion of your post to my blog?


Blog Message http://bbs23.hcwang.cn/home.php?mod=space&uid=3982647&do=profile&from=space

What would you like to see out of a creative writing short story?


Blog Message http://bbs23.hcwang.cn/home.php?mod=space&uid=4007261&do=profile&from=space

Pretty! This was a really wonderful post. Many thanks for providing this info.


Blog Message https://www.suba.me/

prTiAs Some really quality blog posts on this site, saved to fav.

First Previous 1 2 3 4 5 6 Next Last 
Rating
Name
Email
Comment