Search code examples
vb.netwinformsdynamic-text

vb.net add text to form without interaction


I have a winform project which lists all the files in a specified folder. It allows the user to select a new destination for each file, and when the user has chosen the destinations for all files that he would like to be moved, it moves the files, one by one.

My next step is, I need to display a confirm form when the files are being moved, and add each file's name and destination to the confirm form as it is being moved.

My question is: How can I add more text to the confirm form's controls after I already loaded it (using confirm.showdialog() from my other form, without any user interaction? I imagine that I need to do it from the original form, because it needs to display each one when it starts to move that file, but I'm open to any suggestions:)

TIA


Solution

  • Both above answers are good.

    If I understand correctly, your main form will allow one to select multiple files, then select their destination and launch the move process. If that's what you need, I would simply do the following:

    1. Create a new form that would report the process to the user, without requiring any interaction, but just to inform the user what file is being moved;
    2. Create an instance of a BackgroundWorker object, and call the file-move method from the BackgroundWorker.DoWork() method (within your main form);
    3. Flag your BackgroundWorker to report progress, then call the BackgroundWorker.ReportProgress() event handler from within your move-file method;
    4. Use the previously created list of file names to get its name and report it to your file-move dialog form while the file is being changed. A simple DataBinding over a Label should do the trick while you'll move your CurrencyManager to the next item within the list, or you could simpler use the list indexer to get the filename at a particular index;
    5. When the user launches the move process, get your filenames and and count them, then set your ProgressBar Maximum value to the number of files you have.
    6. The BackgroundWorker.ReportProgress() method takes an integer value as its argument, then, with your ProgressChanged() event handler, you will be able to display the name of the file being copied to your window by getting the filename at the index location, index given by your ReportProgress() method.

    This will allow you to use the performance of a supplemental thread, without "freezing" your main thread from which your form has been created, then you will be able to simultaneously perform your file move, and display the filename to the progress-form, while illustrating to your user visually what the progress is about through your ProgressBar control, and displaying the filename as required.

    Does this help?