//-------------------------------------------------------------------------------------- // 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); } }
//-------------------------------------------------------------------------------------- // SaveFunction: The saving function when an image already has a save location. //-------------------------------------------------------------------------------------- private void SaveFunction() { // Get the current tabview TabView tabview = ((TabView)tabControl1.SelectedTab.Controls[0]); // Check if something has a file path or not //if it already does then dont use save dialog and just go ahead and save the file if (tabview.GetNewFile() == false) { if (tabview.GetDirectory() != null) { // Get image and save image to save location. Image image = tabview.GetImage(); image.Save(tabview.GetDirectory()); tabview.SetAltered(false); tabview.SetNewFile(false); } } // The file hasnt been saved before, need thesave dialog else if (tabview.GetNewFile() == true) { SaveAsFunction(); } }
//-------------------------------------------------------------------------------------- // newToolStripMenuItem_Click: What to do when the new 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 newToolStripMenuItem_Click(object sender, EventArgs e) { // Create and display a new forms for options on creating the new project. var form2 = new Form2(); form2.StartPosition = FormStartPosition.CenterParent; form2.ShowDialog(); // If the okay button is pressed. if (form2.GetOkayPressed()) { // Create new tab TabView tabview = NewTab("New Image"); // Create new bitmap Bitmap bitm = new Bitmap(form2.GetImageWidth(), form2.GetImageHeight(), PixelFormat.Format32bppArgb); // Let the user pick a width and hieght in a seperate form. // Set the background of the picturebox. tabview.SetBackgroundColor(form2.GetImageColor()); // Set image on the tabview tabview.SetImage(bitm); // Set the new file to true. tabview.SetNewFile(true); } }
//-------------------------------------------------------------------------------------- // 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); } }