private void MainForm_Load(object sender, EventArgs e) { // Do some initialization m_strDicomFilesFolder = ""; m_DicomDir = new UserDicomDir(); // Add a RasterImageViewer in the same location as txtElementValue rasterImageViewer1 = new ImageViewer(); rasterImageViewer1.Visible = false; groupBox3.Controls.Add(rasterImageViewer1); rasterImageViewer1.Location = txtElementValue.Location; rasterImageViewer1.Size = txtElementValue.Size; rasterImageViewer1.Zoom(ControlSizeMode.Fit, rasterImageViewer1.ScaleFactor, rasterImageViewer1.DefaultZoomOrigin); txtElementValue.SendToBack(); UpdateUI(true); Application.ApplicationExit += new EventHandler(Application_ApplicationExit); }
/* * Loads an existing DICOMDIR file */ private void btnLoad_Click(object sender, EventArgs e) { MainForm.cancel = false; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "DICOMDIR|DICOMDIR|All Files|*.*"; ofd.FilterIndex = 0; if (ofd.ShowDialog() != DialogResult.OK) { return; } // Reset and clear rasterImageViewer1.Visible = false; rasterImageViewer1.Image = null; trvDicomDir.Nodes.Clear(); m_DicomDir.Reset(""); m_strDicomFilesFolder = ""; txtElementValue.Text = ""; txtDirectory.Text = ""; SetStatus(""); Invalidate(); // Get the root directory of this DICOMDIR m_strDicomFilesFolder = ofd.FileName.Substring(0, ofd.FileName.LastIndexOf("\\")); txtDirectory.Text = m_strDicomFilesFolder; if (!File.Exists(ofd.FileName)) { MessageBox.Show("File does not exist."); return; } // Load the file and populate the TreeView try { m_DicomDir.Load(ofd.FileName, DicomDataSetLoadFlags.LoadAndClose); if (m_DicomDir.DataSet.InformationClass != DicomClassType.BasicDirectory) { MessageBox.Show("Please select a valid Dicom Directory file."); m_DicomDir = new UserDicomDir(); return; } try { FillTreeKeys(null, null); } catch (Exception ex) { MessageBox.Show("Error while populating tree:\r\n\r\n" + ex.ToString()); } SetStatus("DICOMDIR successfully loaded"); } catch (Exception ex) { SetStatus(string.Format("Status: Failed to add file to the DICOM Directory! (Error Message: {0}) Make sure that this is a valid Dicom DataSet.", ex.Message)); return; } }