473,491 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Forms

Hi,

I asked this question before, but didn't get the answer I
was looking for, so I'm hoping if I re-phrase it it'll
make more sense.

I'm trying to write a MultiReplace program that will
replace a word or phrase in multiple text files. I have
written most of the code to do this, but I want to
display a progress bar to the user as it goes through the
files.

I've designed a simple form with a progress bar and a
cancel button that I wish to display as the replace code
is running.

At the moment I have a main dialog window which allows
the user to specify what they want to find and replace.
When they click the "Replace" button in this dialog, it
creates an instance of my second dialog (the one with the
progress bar) and calls the .ShowDialog method on it.
Now I need to know how to run my "replace" code once the
second dialog has displayed, since the .ShowDialog method
won't return until the second dialog has closed. I know
I could use the .Show method, but I want the dialog to be
modal.

I hope this makes sense.

Cheers,
Burns
Nov 15 '05 #1
2 2736
Hi,

You should use a worker thread to do the find/replace operation while the
main thread is running the progress bar dialog, you also needs some form of
sync between them, basically you must have two events, if the user press
cancel you should inform the worker thread of it, and the worker thread
should inform the dialog when it finish.

Also you said that you use ShowDialog therefore either you create the thread
from the Progress bar dialog itself ( I would do this ) or you have to
create and start it before you call ShowDialog.

regarding of how to do the progress bar, well it's very simple, you just
use a timer and on each interrupt you increment the ProgressBar.Value if it
become the MaxValue you equal it to the MinValue.

Warning:
The code below is just to give you an idea, I'm not working now on my
machine and cannot be sure of the exact signature of the methods/properties
or events, so do not copy it verbatin and rather get the general idea.

I would use two flags ( bool variables ) to indicate both a cancel operation
or a Finish event , you may use events too, but IMHO the flags are easiers.
In the timer handler you will check for the finish flag, if it's then you
are done and can close the form, otherwise you just increment the value, I
used a variable "finito" to this purpose, you declare it as:

bool finito = false;

later I will show you how you set it.

public TimerEvent( object sender, )
{
if ( finito )
{
timer.enabled = false;
this.Close();
return;
}

// check the current value and increment it
progressBar.Value = progressBar.Value + 1;

}
The Cancel handler is extremely simple, just a line:

{
cancelSearch = true;
}

the variable cancelSearch is declared in the same way that "finito"

now, the worker thread is the most interesting part of all, it keeps
searching on the files and at the same time checks for the cancelSearch
flag:

protected void DoSearch()
{

while ( ( (currentfile = GetNextFile() )!= null ) && (cancelSearch ==
false)
{
//do the search
}
//inform the dialog we finished the search, either by cancel or by end
of the file list
finito = true;
}
As you can see , it;s very symple too, just iterate and at the end set the
flag to true. it will be picked up in the next tick event and the dialog
will close itself.


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
I asked this question before, but didn't get the answer I
was looking for, so I'm hoping if I re-phrase it it'll
make more sense.
A similar answer to this was answered last week IIRC.
I'm trying to write a MultiReplace program that will
replace a word or phrase in multiple text files. I have
written most of the code to do this, but I want to
display a progress bar to the user as it goes through the
files.

I've designed a simple form with a progress bar and a
cancel button that I wish to display as the replace code
is running.

At the moment I have a main dialog window which allows
the user to specify what they want to find and replace.
When they click the "Replace" button in this dialog, it
creates an instance of my second dialog (the one with the
progress bar) and calls the .ShowDialog method on it.
Now I need to know how to run my "replace" code once the
second dialog has displayed, since the .ShowDialog method
won't return until the second dialog has closed. I know
I could use the .Show method, but I want the dialog to be
modal.

I hope this makes sense.

Cheers,
Burns

Nov 15 '05 #2
You my friend, are a star. Thanks very much.

Peace,
Burns
Nov 15 '05 #3

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

Similar topics

19
4064
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
2266
by: Joshua Russell | last post by:
Hi, Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of...
7
2452
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
13
5539
by: MD | last post by:
I have been converting a program from VB6 to VB.Net and enhancing it as well. All has been progressing OK although its been hard work. Now, all of a sudden, when I try to execute a ShowDialog()...
15
2026
by: Joshua Kendall | last post by:
I have a script in which it keeps opening the same form instead of only one instance. I also need help with a form that has a password. Where do I put the actual password? can I use a database for...
3
1625
by: Lloyd Sheen | last post by:
I have the following situation: Need a user resizable user control. After much trying with user control I came across the idea of hosting the controls in a form marked as not TopLevel = false. ...
8
2699
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
3
2355
by: Geraldine Hobley | last post by:
Hello, In my project I am inheriting several forms. However when I inherit from a form and add additional subroutines and methods to my inherited form I get all sorts of problems. e.g. I sometimes...
6
2551
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
21
3284
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
6978
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...
0
7190
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...
1
6858
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
7360
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
5451
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,...
1
4881
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...
0
4578
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...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
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 ...

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.