473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

progress bar

How to use progressBar with loading picture into pictureBox.

Code:

private void InitializeMyTimer()

{

// Set the interval for the timer.

time.Interval = 250;

// Connect the Tick event of the timer to its event handler.

time.Tick += new EventHandler(IncreaseProgressBar);

// Start the timer.

string fName = "F:\\ReportLogo\\pictures\\Coffee Bean.bmp";

try

{

time.Start();

pb.Image = System.Drawing.Image.FromFile(fName);

}

catch (Exception x)

{

MessageBox.Show(x.Message);

}

}

What's wrong?
Oct 13 '06 #1
3 12315
pb.Image = System.Drawing.Image.FromFile(fName);

I suspect that your UI thread is waiting for the this operation to complete;
one option is to obtain the image on a different thread, and then sync back
afterwards. Also note the use of a marquee to avoid a timer.

Marc
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;

class Program
{
class ImageForm : Form
{
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new ImageForm());
}
private ProgressBar pb;
public ImageForm()
{
Button button = new Button();
button.Text = "Load";
Controls.Add(button);
button.Click += new EventHandler(button_Click);
pb = new ProgressBar();
pb.Dock = DockStyle.Bottom;
pb.Style = ProgressBarStyle.Marquee;
pb.Visible = false;
Controls.Add(pb);
}

void button_Click(object sender, EventArgs e)
{
pb.Visible = true;
ThreadPool.QueueUserWorkItem(LoadImage);
}
private void LoadImage(object state)
{
Thread.Sleep(5000); // to make it look slower to demo
Image img = Image.FromFile(@"C:\WINDOWS\Coffee Bean.bmp");
Invoke((MethodInvoker) delegate {
BackgroundImage = img;
pb.Visible = false;
});
}
}
}
Oct 13 '06 #2
Thank you.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:uG**************@TK2MSFTNGP03.phx.gbl...
>pb.Image = System.Drawing.Image.FromFile(fName);

I suspect that your UI thread is waiting for the this operation to
complete; one option is to obtain the image on a different thread, and
then sync back afterwards. Also note the use of a marquee to avoid a
timer.

Marc
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;

class Program
{
class ImageForm : Form
{
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new ImageForm());
}
private ProgressBar pb;
public ImageForm()
{
Button button = new Button();
button.Text = "Load";
Controls.Add(button);
button.Click += new EventHandler(button_Click);
pb = new ProgressBar();
pb.Dock = DockStyle.Bottom;
pb.Style = ProgressBarStyle.Marquee;
pb.Visible = false;
Controls.Add(pb);
}

void button_Click(object sender, EventArgs e)
{
pb.Visible = true;
ThreadPool.QueueUserWorkItem(LoadImage);
}
private void LoadImage(object state)
{
Thread.Sleep(5000); // to make it look slower to demo
Image img = Image.FromFile(@"C:\WINDOWS\Coffee Bean.bmp");
Invoke((MethodInvoker) delegate {
BackgroundImage = img;
pb.Visible = false;
});
}
}
}


Oct 13 '06 #3
A meaningless progress bar is worse than no progress bar at all. If all
you need is to let the user know your app is "thinking" and not frozen,
consider just displaying a animated circle graphic.

Think of installing office 2000; it was "done" five times in a row.
Think of installing IE7 "WTF is this little block going back and forth?"

The apple mac "petal" style indicator is quite nice and non-annoying in
these situations. My thunderbird nntp client has even stolen it. ;)

~Jason

--
Oct 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SpamProof | last post by:
I got an animated gif that is a barber pole spinning that I want to use as a progress bar. The problem is that is stops spinning (shows 1 frame) when my browser is processing a submited request...
7
by: Pepi Tonas | last post by:
I have a form that takes some time to load because it has to populate some Data. I was trying to display a form on top of it with an activity bar so that user can see that something's going on. ...
1
by: scorpion53061 | last post by:
this code came from cor and I think Armin authored it. I am trying to download an access database and track its progress. It is reading the size fo the file but I am unsure of how to get the...
8
by: Brian Henry | last post by:
I created a smooth progress bar with this code.. but if you update the values in a row quickly of it and watch it on screen it flickers... how would i change this to reduce the flickering?...
8
by: WhiteWizard | last post by:
I guess it's my turn to ASK a question ;) Briefly my problem: I am developing a Windows app that has several User Controls. On one of these controls, I am copying/processing some rather large...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
15
by: eladla | last post by:
Hi! I am creating a composite control the does some of it`s own data access. I want to display a progress bar between the time the page is loaded and the control place holder is displayed and...
5
by: Aggelos | last post by:
Hello I am doing sevreral scripts like sending a newsletter that might take a while to finish first to prevent the browser from timing out and to keep the user informed of the process progress I...
1
by: Bob | last post by:
Hi, I am having trouble seeing how this bolts together. The UI starts a process which involves a long running database update. All Database activity is handled by a class called DT. DT has a...
0
by: jags_32 | last post by:
Hello We use MFG-PRO as our ERP system which in turn uses Progress databases. In the old version of SQL 2000, using DTS packages, we used to set the code page via command prompts and execute DTS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.