private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
string outputPngPath = Path.Combine(Path.GetDirectoryName(file), "output.png");
using (var viewer = new Viewer(file))
{
PngViewOptions viewOptions = new PngViewOptions();
viewOptions.CadOptions.BackgroundColor = Color.FromArgb(224, 224, 224);
viewer.View(viewOptions);
// Dosya adını ve uzantısını al
string fileName = Path.GetFileName(file);
string extension = Path.GetExtension(file);
// Sadece dwg ve dxf dosyalarını işle
if (extension == ".dwg" || extension == ".dxf")
{
// Dosya adındaki adet ve mm değerlerini ayrıştır
string[] parts = fileName.Split('-', '.', '_', '*');
string mmValue = "";
string adetValue = "";
foreach (string part in parts)
{
if (part.ToUpper().Contains("MM"))
{
mmValue = part.Replace("MM", "").Trim();
}
else if (part.ToUpper().Contains("ADET"))
{
adetValue = part.Replace("ADET", "").Trim();
}
}
using (PictureBox pictureBox = new PictureBox())
{
pictureBox.BackgroundImage = Image.FromFile(outputPngPath);
Image resizedImage = ResizeImage(pictureBox.BackgroundImage, 150, 50);
// DataGridView'e yeni satır ekle
dataGridView1.Rows.Add(fileName, extension, mmValue, "", "", adetValue, "", resizedImage);
}
}
viewOptions.WordProcessingOptions.RenderTrackedChanges = true;
}
}
}
}
private void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
}
Hello, I’m developing a program using C# Windows Forms. What I want to do is to drag and drop only .dwg and .dxf files into a DataGridView and display the corresponding file’s images in each row. I have accomplished everything so far, but I have a few issues. I’m unable to change the drawing color of the image added to the PictureBox, and I would like to retrieve the actual dimensions (maximum width and height) of the files I upload. Thank you in advance for your support.
Ekran görüntüsü 2023-05-12 121440.png (66.4 KB)