473,789 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1458
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 ProgressEventHa ndler(int percentComplete );

Then, in your data module (class), do something like this:
public MyDataClass
{
public event ProgressEventHa ndler 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(mypr ogresspercent);
}
}
}
Then, in your main form, you define the method to handle the event:

MyDataClass myDataClass = new MyDataClass();
myDataClass.OnP rogress += new ProgressEventHa ndler(MyProgres sHandler);
...
private void MyProgressHandl er(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****@discuss ions.microsoft. com> wrote in message
news:C3******** *************** ***********@mic rosoft.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
4109
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, if I wanted to have a percentage progress counter that was constantly updating. I'm unsure how to do this without printing to a brand new line. Any help would be greatly appreciated. Thanks. Daniel
6
3987
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 script is running. Is this possible to do with a textbox? I've tried using the response.flush with a variable which kinda works but it displays as follows; 1000 2000 3000
2
11789
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 named SplashScreen, and a C# class library named BackgroundProcess.
2
6311
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 steps can take seconds to process, but others could take upto 10 minutes (leaving the users thinking nothing is happening!). Is there a way to show the progressbar smoothly increasing until the final step has finished instead of clunking it's way...
8
19633
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. pBar1.Minimum = 1; // Set Maximum to the total number of files to copy. pBar1.Maximum = 4; //filenames.Length;
1
5427
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 (form called ProgressForm) and the built the dll. Then I reference this new assembly from within my asp.net applicaiton and tried to access Windows.Forms.ProgressBar from within the ProgressForm but apparently it doesn't work. Because it won't...
2
3188
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
329
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 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?
6
1876
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 program and tries to come back. The multithreading stuff is looking somewhat complicated. Can somebody show me a pre-built function on how to continuously update a status bar while another process is running. Should I run the database process on a...
0
9499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10124
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8998
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5540
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4078
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.