vb.net 添加文本到表单,无需交互

发布于 2024-08-25 10:08:33 字数 301 浏览 4 评论 0原文

我有一个 winform 项目,其中列出了指定文件夹中的所有文件。它允许用户为每个文件选择一个新的目的地,当用户为他想要移动的所有文件选择目的地时,它会一个接一个地移动文件。

我的下一步是,我需要在移动文件时显示确认表单,并在移动文件时将每个文件的名称和目的地添加到确认表单中。

我的问题是: 在加载确认表单后,如何向其控件添加更多文本(使用其他表单中的 confirm.showdialog() ,无需任何用户交互?我想我需要从原始形式,因为它需要在开始移动该文件时显示每一个,但我愿意接受任何建议:)

TIA

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

牵你手 2024-09-01 10:08:33

上面两个答案都很好。

如果我理解正确,您的主窗体将允许您选择多个文件,然后选择它们的目的地并启动移动过程。如果这就是您所需要的,我只需执行以下操作:

  1. 创建一个新表单,向用户报告该过程,不需要任何交互,而只是通知用户正在移动什么文件;
  2. 创建一个BackgroundWorker对象的实例,并从BackgroundWorker.DoWork()方法(在主窗体中)调用文件移动方法;
  3. 标记您的BackgroundWorker以报告进度,然后从您的移动文件方法中调用BackgroundWorker.ReportProgress()事件处理程序;
  4. 使用先前创建的文件名列表来获取其名称,并在更改文件时将其报告给文件移动对话框。当您将货币管理器移动到列表中的下一个项目时,通过标签进行简单的数据绑定应该可以解决问题,或者您可以更简单地使用列表索引器来获取特定索引处的文件名;
  5. 当用户启动移动过程时,获取您的文件名并计算它们,然后将您的进度条最大值设置为您拥有的文件数。
  6. BackgroundWorker.ReportProgress() 方法采用整数值作为其参数,然后,使用 ProgressChanged() 事件处理程序,您将能够通过获取索引位置处的文件名来显示复制到窗口的文件的名称,由 ReportProgress() 方法给出的索引。

这将允许您使用补充线程的性能,而无需“冻结”创建表单的主线程,然后您将能够同时执行文件移动,并将文件名显示到进度表单,同时通过 ProgressBar 控件向用户直观地说明进度,并根据需要显示文件名。

这有帮助吗?

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?

萌能量女王 2024-09-01 10:08:33

制作另一种表单而不是使用预设对话框不是更简​​单吗?

这样你就可以有一个填充和刷新的文本框

Wouldn't it be simpler to make another form instead of using preset dialogs?

that way you can just have a textbox that you populate and refresh

忆悲凉 2024-09-01 10:08:33

您可以将所有代码放在确认对话框窗口中以显示文件的移动。

但为了提供更完整的解决方案,您能否告诉我您如何收集文件移动信息。

一个好的解决方案是只传递要移动的文件列表,然后在对话框中执行移动功能。

You could do put all of the code to show the moving of the files inside the confirm dialog window.

But to give a more complete solution could you tell me how you are gathering the file moving information.

A Good solution would be to just pass in the list of the files to be moved and then perform the moving function in the dialog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文