Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

ProgressBar incremented from outside of Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mamin@o2.pl - 29 Nov 2006 11:59 GMT
I have, the following question:

I have a WindowsForm with ProgressBar  progressBar1 and Button button1.
After onClick event on  button the following method executes:

button_Click(object sender, EventArgs e)
{
    DatabaseOperations.ClearDatabase();
}

where ClearDatabase() is static method which should increment my
progress bar. How can I increment my progress bar without giving
ProgressBar object as parameter( I mean without using
ClearDatabase(progressBar1); - it doesn't seem to be a good way)

Thanks for any reply.
Jon Skeet [C# MVP] - 29 Nov 2006 22:36 GMT
> I have, the following question:
>
[quoted text clipped - 10 lines]
> ProgressBar object as parameter( I mean without using
> ClearDatabase(progressBar1); - it doesn't seem to be a good way)

You'll need to provide *something*. If you want to decouple
DatabaseOperations from the UI (which is reasonable) you could give
DatabaseOperations a DatabasedClearProgress event which the UI could
subscribe to, and which ClearDatabase could raise.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

mamin@o2.pl - 30 Nov 2006 08:48 GMT
> You'll need to provide *something*. If you want to decouple
> DatabaseOperations from the UI (which is reasonable) you could give
> DatabaseOperations a DatabasedClearProgress event which the UI could
> subscribe to, and which ClearDatabase could raise.

But how can I raise ProgressBar event from this static method?
Jon Skeet [C# MVP] - 30 Nov 2006 18:47 GMT
> > You'll need to provide *something*. If you want to decouple
> > DatabaseOperations from the UI (which is reasonable) you could give
> > DatabaseOperations a DatabasedClearProgress event which the UI could
> > subscribe to, and which ClearDatabase could raise.
>
> But how can I raise ProgressBar event from this static method?

You'd make the DatabaseClearProgress event static as well. It wouldn't
be a ProgressBar event - it would just be that the handler the UI added
would happen to update the progress bar.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Thomas T. Veldhouse - 30 Nov 2006 19:02 GMT
> I have, the following question:
>
[quoted text clipped - 10 lines]
> ProgressBar object as parameter( I mean without using
> ClearDatabase(progressBar1); - it doesn't seem to be a good way)

I think the issue is that ClearDatabase() should probably NOT be static.  You
could create a database "engine" and then have an event on it to indicate
status, completion, what have you.  Then subscribe to them from your UI and
have the event handler post to the progress bar.

Signature

Thomas T. Veldhouse
Key Fingerprint: D281 77A5 63EE 82C5 5E68  00E4 7868 0ADC 4EFB 39F0

Jon Skeet [C# MVP] - 30 Nov 2006 20:35 GMT
> I think the issue is that ClearDatabase() should probably NOT be static.  You
> could create a database "engine" and then have an event on it to indicate
> status, completion, what have you.  Then subscribe to them from your UI and
> have the event handler post to the progress bar.

While I agree that it would be good to have a database engine instance,
there's nothing to stop the OP from having a static event.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.