473,397 Members | 1,985 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,397 software developers and data experts.

Updating ProgressBar value from within a class.

I have a module which performs data processing job and as each row is
processed progress bar value is incremented. Now I have moved this module in
a separate class. How can I increment the value progress bar which resides on
the main form?

Do I have to pass the progress bar to my class, or there’s some other way?

Jul 21 '05 #1
1 1432
SB
There are many ways to do this of course, but I prefer to use
delegates/events. Off the top of my head, here is a brief explanation on
how to do it:
Somewhere in the namespace or within a class, declare a public delegate that
defines what the method signature looks like:
public delegate void ProgressEventHandler(int percentComplete);

Then, in your data module (class), do something like this:
public MyDataClass
{
public event ProgressEventHandler OnProgress;

....

// fire the event at whatever point you want to..say in this method
public void DoSomeWork()
{
// do some work...then fire the event
if (OnProgress != null)
{
OnProgress(myprogresspercent);
}
}
}
Then, in your main form, you define the method to handle the event:

MyDataClass myDataClass = new MyDataClass();
myDataClass.OnProgress += new ProgressEventHandler(MyProgressHandler);
...
private void MyProgressHandler(int percentComplete)
{
// update your progress bar here.
}

Hopefully the above makes sense :) Anyway, I recommend you do a little
research on delegates and events and see what they have to offer. In the
end, they are more flexible than other paradigms.

-sb

"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
I have a module which performs data processing job and as each row is
processed progress bar value is incremented. Now I have moved this module
in
a separate class. How can I increment the value progress bar which resides
on
the main form?

Do I have to pass the progress bar to my class, or there's some other way?

Jul 21 '05 #2

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

Similar topics

3
by: Daniel Pryde | last post by:
Hi there. I hope this isn't a stupid question to ask, but does anyone know how to print out a string without moving to a new line each time and simply updating the first line. An example would be,...
6
by: rob | last post by:
Hi All, I have an asp script which updates upto 300000 records each time it is run. I would like to have a textbox which says records progressed : then in increments of 100 or 1000 whilst the...
2
by: BG | last post by:
We're having trouble writing the code to update a UI control (label.Text) from a secondary thread. We're using C# with Windows Forms. We have a main form named MainForm, a splash screen form...
2
by: jez123456 | last post by:
Hi, thanks for the previous advice on progressbars with showing the percentage. I would now like to create a less clunky version. I.e at the moment my progressbar shows 7 separate steps. Some...
8
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied....
1
by: Mehr H | last post by:
I've been trying to figure out how i can embed a Windows.Forms.ProgressBar in my webform (aspx) file. I have tried putting a Windows.Forms.ProgressBar as public on a regular winform designer form...
2
by: Bill Nguyen | last post by:
How can I create a shared function to display process progress that can be called from other routines within an application? Any example that I can follow? Thanks Bill
1
by: Job Lot | last post by:
I have a module which performs data processing job and as each row is processed progress bar value is incremented. Now I have moved this module in a separate class. How can I increment the value...
6
by: Derek Hart | last post by:
I am using a status bar to show progress for a long database update. With the single threading, the GUI often gets stuck and does not show updating, especially when the user clicks to another...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.