Hi @Farshad Valizade , Welcome to Microsoft Q&A,
- Make sure the file dialog allows multiple file selections (
openFileDialog1.Multiselect = true
). - Get the list of files selected by the user and set the progress bar's maximum value to the number of files (
progressBar1.Maximum = files.Length
). - After each file is converted, increase the progress bar's value (
progressBar1.Value++
). - After all files have been processed, set the progress bar's value to the maximum value and display a completion message.
using System;
using System.IO;
using System.Windows.Forms;
namespace YourNamespace {
public partial class YourForm: Form {
public YourForm() {
InitializeComponent();
}
private void btnConvert_Click(object sender, EventArgs e) {
try {
openFileDialog1.Filter = "Dwg Files(*.dwg)|*.dwg";
openFileDialog1.Multiselect = true; // Ensure multiple selections are allowed
if (openFileDialog1.ShowDialog(this) != DialogResult.OK) return;
string[] files = openFileDialog1.FileNames;
if (files.Length == 0) return;
progressBar1.Minimum = 0;
progressBar1.Maximum = files.Length;
progressBar1.Value = 0;
progressBar1.Visible = true;
foreach(var file in files) {
CadDocument doc = DwgReader.Read(file);
doc.Header.Version = ACadVersion.AC1032;
string dxfPath = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".dxf");
using(DxfWriter writer = new DxfWriter(dxfPath, doc, false)) {
writer.OnNotification += onNotification;
writer.Write();
}
// Update progress bar
progressBar1.Value++;
}
progressBar1.Value = progressBar1.Maximum;
MessageBox.Show("All files converted! ");
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void onNotification(object sender, NotificationEventArgs e) {
// Handle notification events
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.