//-------------------------------------------------------------------------------------- // openToolStripMenuItem_Click: What to do when the open button is pressed under the menu bar. // // Param: // sender: object type, Supports all classes in the .NET Framework class hierarchy. // e: EventArgs type, represents the base class for classes that cotain event data. //-------------------------------------------------------------------------------------- private void openToolStripMenuItem_Click(object sender, EventArgs e) { // New open file dialog. OpenFileDialog dlg = new OpenFileDialog(); string filename = ""; // Filter which files can be opened. dlg.Filter = "BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff|" + "All Files|*.*"; // Present the open dialog if (dlg.ShowDialog() == DialogResult.OK) { // store the file path. filename = dlg.SafeFileName; // Create a new tab TabView tabview = NewTab(filename); // Set image to the new tabview. Bitmap bitm = new Bitmap(Image.FromFile(dlg.FileName)); tabview.SetImage(bitm); tabview.SetDirectory(dlg.FileName); tabview.SetNewFile(true); } }
//-------------------------------------------------------------------------------------- // Form1_DragDrop: Function for what to do when something is drag dropped. // // Param: // sender: object type, Supports all classes in the .NET Framework class hierarchy. // e: DragEventArgs type, represents the base class for classes that cotain event data. //-------------------------------------------------------------------------------------- private void Form1_DragDrop(object sender, DragEventArgs e) { // if a valid file has been dropped. if (isDataValid) { // while the thread is still running. while (imageThread.IsAlive) { Application.DoEvents(); // Block the current thread Thread.Sleep(0); } // Create a new tab TabView tabview = NewTab(System.IO.Path.GetFileName(filepath)); // Set image to the new tabview. tabview.SetImage(image); tabview.SetDirectory(System.IO.Path.GetFileName(filepath)); } }
//-------------------------------------------------------------------------------------- // SaveAsFunction: The saving function when an image doesnt have a saved file. //-------------------------------------------------------------------------------------- private void SaveAsFunction() { // New save dialog SaveFileDialog save = new SaveFileDialog(); // Filter which files can be saved. save.Filter = "PNG|*.png|BMP|*.bmp|GIF|*.gif|JPG|*.jpg|JPEG|*.jpeg|TIF|*.tif|TIFF|*.tiff"; // Set image format ImageFormat format = ImageFormat.Png; // Show dialog box. if (save.ShowDialog() == DialogResult.OK) { //get filename extensions. string ext = System.IO.Path.GetExtension(save.FileName); switch (ext) { // png. case ".png": format = ImageFormat.Png; break; // bmp. case ".bmp": format = ImageFormat.Bmp; break; // gif. case ".gif": format = ImageFormat.Gif; break; // jpg. case ".jpg": format = ImageFormat.Jpeg; break; // jpeg. case ".jpeg": format = ImageFormat.Jpeg; break; // tif. case ".tif": format = ImageFormat.Tiff; break; // tiff. case ".tiff": format = ImageFormat.Tiff; break; } // Get the current tabview TabView tabview = ((TabView)tabControl1.SelectedTab.Controls[0]); // Get image and save image to save location. Image image = tabview.GetImage(); image.Save(save.FileName, format); // Set altered and new to false tabview.SetAltered(false); tabview.SetNewFile(false); tabview.SetDirectory(save.FileName); // Set the tab name tabControl1.SelectedTab.Text = System.IO.Path.GetFileName(save.FileName); } }