TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Casey McCarthy
NA
3
4.2k
pictureBox image load time link to progressbar
May 8 2012 3:22 PM
I've created a simple image viewer and want to link my load time of the image that is being opened in a pictureBox to a progress bar. Here is what I have:
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 ImageViewer
{
public partial class Form1 : Form
{
ProgressBar pBar = new ProgressBar();
Label pLabel = new Label();
BackgroundWorker backgroundWorker1 = new BackgroundWorker();
ProgressBar progressBar1 = new ProgressBar();
public Form1()
{
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
CreateProgressBar();
CreateLabel();
Shown += new EventHandler(Form1_Shown);
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
}
private void CreateLabel()
{
pLabel.Location = new System.Drawing.Point(500, 16);
pLabel.Text = "Progress";
Controls.Add(pLabel);
}
private void CreateProgressBar()
{
pBar.Location = new System.Drawing.Point(550, 13);
pBar.Name = "progressBar1";
pBar.Text = "Progress";
pBar.Width = 300;
pBar.Height = 20;
pBar.Minimum = 0;
pBar.Maximum = 100;
Controls.Add(pBar);
}
private void folderPath_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.FileName = "";
open.Filter = "Image Files(*.tif; *.jpg; *.jpeg; *.gif; *.bmp)|*.tif; *.jpg; *.jpeg; *.gif; *.bmp";
open.InitialDirectory = @"g:\All Scanned Jobs\";
if (open.ShowDialog() != DialogResult.Cancel)
{
// display image in picture box
pictureBox1.Image = new Bitmap(open.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.WaitOnLoad = false;
pictureBox1.LoadAsync(open.FileName);
}
}
void Form1_Shown(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
var num = 0; // I NEED TO STORE THE IMAGE LOAD TIME HERE I THINK
int time = Convert.ToInt32(num);
for (int i = time; i <= 100; i++)
{
backgroundWorker1.ReportProgress(i);
}
}
void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
pBar.Value = e.ProgressPercentage;
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
pictureBox1.Refresh();
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
pictureBox1.Refresh();
}
}
}
Reply
Answers (
1
)
Help, what list control to choose ?
How to Make Crystal reports in C# Windows Application