Possible Duplicate:
How to fix the flickering in User controls
I am currently working on a program that dynamically loads in an Image for the Background image of the form. I want the form to be visible as soon as the image is fully applied to the background.
I've tried the form event BackgroundImageChanged
but this didn't work.
If the image is high resolution I can see the form showing up and the image is still building up itself.
The code snippet:
this.backgroundImage = loadedImage;
// Thread.Sleep(5000);
this.Show();
As you can see I am using Thread.Sleep()
to win some time to fully load the image before showing the form. but is there a way like this :
this.backgroundImage = loadedImage;
while( imageIsNotFullyLoaded() ) { }
this.Show();
Or is there any other method or an event that I haven't seen yet?
EDIT:
my code:
forn1.cs :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace GameClient {
public partial class FormMain:Form {
getImage _getImage;
public FormMain() {
InitializeComponent();
}
private void FormMain_Load( object sender, EventArgs e ) {
_getImage = new getImage();
Image splashLogo = _getImage.fromURL( "http://ace-acid.no-ip.org/GameClient/splash.png" );
this.BackgroundImage = splashLogo;
Thread.Sleep(3000);
this.Show();
}
private void btnLogin_Click( object sender, EventArgs e ) {
this.Hide();
}
}
}
getImage.cs :
using System;
using System.Drawing;
using System.IO;
using System.Net;
namespace GameClient {
class getImage {
public Image fromURL( string URL ) {
Image tmpImg = null;
try {
HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create( URL );
request.AllowWriteStreamBuffering = true;
request.Timeout = 20000;
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
tmpImg = Image.FromStream( stream );
response.Close();
} catch( Exception ex) {
return null;
}
return tmpImg;
}
}
}