|
Hello everybody,
(after pressing a button) i would like to show an image (using a picturebox), wait a few seconds and then play a
mp3 sound, but i dont get it to work. To wait a few seconds i use "System.Threading.Thread.Sleep(5000)". The problem is, the image alway appears AFTER the wait time, but i want it to show first, then wait, then play the mp3... i tried to use "WaitOnLoad = true" but it doesnt work, shouldn't it load the image first and the continue to read the next code line ??
Here is the code i've tried, that doesnt work:
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.WaitOnLoad = true;
pictureBox1.Load("image.jpg");
System.Threading.Thread.Sleep(5000);
MessageBox.Show("test"); //just to test, here should be the code to play the mp3
}
(i also tried loading the image with "LoadAsync" and put the code to wait and play the mp3 in the "LoadCompleted" event, but that doesnt work either...)
would be very nice if somebody helps me
|
|
|
|
|
After you've loaded your image, and before the call to Thread.Sleep() you need to call Application.DoEvents() to enable your form to be updated with the image.
pictureBox1.Load("image.jpg");
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(5000);
|
|
|
|
|
thank you a lot for the answer !!!!
it works now
|
|
|
|
|
calling DoEvents() like that is a hack one should avoid. There are two correct ways to solve such problems:
1. use a timer, preferably a System.Windows.Forms.Timer if the delayed action relates to the GUI;
2. use a separate thread (e.g. a BackgroundWorker), this time with proper Control.InvokeRequired/Imvoke (see here[^]).
Both take a little more effort, but will not fail you, as DoEvents() would when your app becomes somewhat more complex.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Luc Pattyn wrote: as DoEvents() would when your app becomes somewhat more complex.
I'm not disputing your statement but do you have anything to back this (your threading articles live in some of my apps), link, white paper etc.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
No, I don't have any backup, except for logic reasoning: DoEvents() runs another message loop, which means the message queue becomes active while probably executing an event handler already, potentially and unexpectedly turning its caller in a re-entered method, which risks all kinds of things, e.g. to upset your object's state, and maybe even to overflow the stack (imagine DoEvents inside a MouseMove handler).
I would avoid DoEvents() as much as possible, as it is very dangerous; and I would typically not need to call it, as I tend to use threads for most everything except actions that will always finish in a few milliseconds.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
[^]
Guess it doesn't hurt to ask everywhere possible.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
BillWoodruff wrote: ask everywhere possible
That is the best way to get more wrong answers... the first one is correct and rather creative, not the way I would recommend though. The rest just stinks.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
try this idea
//load your picture
//create a timer then set ur time
//create a mp3 player
//play your sounds
thats it
|
|
|
|
|
how to display continuous data to editbox(edit control)
i had done several program, but unsuccessful.
what i want to use is, when the radio button been click(tick), the data will always been display(not only 1 data but keep changing data) on edit box(edit control) and when the radio button been click(not tick) the display at edit box(edit control) will stop.
anyone can help me..
A.S.A.P
thanks
|
|
|
|
|
You just need to set a variable to allow the edit to continue until the radio button changes. Trap the CheckedChanged event in your radio button and either set or clear the variable to indicate what to do in the edit box.
zaftblitz wrote: the data will always been display(not only 1 data but keep changing data) on edit box(edit control)
Your question is not very clear so I do not quite understand what you mean by the above.
MVP 2010 - are they mad?
|
|
|
|
|
what i mean is i want to display data that will keep changing the value by itself.
|
|
|
|
|
zaftblitz wrote: i want to display data that will keep changing the value by itself.
Wouldn't that be nice? Unfortunately, computers need a little help from we humans. If you need the data in a box to keep changing then you wll need to write some code to do it. The actual mechanism may depend on where the data is coming from, how long it is etc. Without much more detail it is difficult to know what would be the best method to achieve this. I would suggest you try searching among some of the articles here for a few ideas.
MVP 2010 - are they mad?
|
|
|
|
|
I have a windows application that is installed under ProgramFiles folder on Window7 based computer. During the launch of application some questions are asked to the user and written to the .exe.config file using ConfigurationManager.Save() method. This .exe.config file is also in ProgramFiles folder. When a user with Administrator priviledges launch application, everything works fine. But when a Standard User launch same application then application throws ConfigurationErrorsException saying that Access to path .exe.config is denied. It actually points to some .tmp file in same directiory. The name of this tmp file changes ever time user get this error but in the detail of exception always points to .exe.config file. What is the best way of addressing this problem? Remember this config file need to be accessed by all users who login and use this application.
TIA
|
|
|
|
|
The Program Files folder is about the worst place you can put global settings like that. If a normal user doesn't have an admin account, you're out of luck and have to move your settings to somewhere else that is writable by normal users. Think "CommonApplicationData", here[^].
If you're users do have an admin account, then you'd add a manifest file to your project and tell it that the app requires admin priv's to run. This is not the best way to do this since you're essentially forcing users to be an admin on the machine.
|
|
|
|
|
Appreciate your quick reply. So are you suggesting to store .exe.config into CommonApplicationData folder during the installation of project? Can this folder be referred in installed package?
|
|
|
|
|
You can do that or you can have your code create this file on first launch if it doesn't exist. It's up to you.
imak wrote: Can this folder be referred in installed package?
Sure. How you do that depends on which .MSI packaging software you're using. Myself, I use InnoSetup and Wise Package Studio. It don't use the Setup and Deployment stuff in Visual Studio.
|
|
|
|
|
Hello, in Windows XP 64 OS I have my quick launch bar above the taskbar.
When I hover over the quick launch icon I see the tip is behind the bar now that I have it twice as high as normal.
Is there a way to get the tip above the bar?
Thank you,
djj
|
|
|
|
|
How is this related to Windows forms?
BTW you might have set always on top to true for task bar. That should be the reason.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
d@nish wrote: How is this related to Windows forms?
Sorry about that. I saw windows and quit reading I guess.
|
|
|
|
|
I need a program in PHP which can extract the hidden biders from ebay.I will have to insert the item number and the program must show me all bidders of the auction and their emails.
Also the same program must extract the registered contact information for any specified bidder specially the email address
I will pay for this
If someone can help please contact me at totos_back@yahoo.com
Thanks
|
|
|
|
|
You're on the wrong site for that. Try RentACoder.com.
|
|
|
|
|
I have a vb.net that generates a print document with multiple A5 pages. i need to be able to pring two pages per sheet on A4 paper. I am unable to find a property for this in PrintDocument.DefaultPageSettings or anywhere in the PrintDialog settings. Does anyone know a way of acheiving this.
Regards,
Martin
|
|
|
|
|
Hi all
Adobe have an SDK for thier DNG file format which allows developers to code so that DNG file information can be read/written etc but the existing ones that I found where to be compiled for VS 2009, using C++ code
The other was for the MAC O/S
Does anyone know if an SDK for DNG is available for .NET windows forms programming please?
Many thanks in advance.
John
|
|
|
|
|
i want to ask...
can i do serial comunication by using normal window form application using VC++ 2008 because there has an icon in the toolbox show about serialPort..
how ican i do the communication in window form...
|
|
|
|