Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==++Resources Additional Files++==
- Graph.jpg ================= https://www.dropbox.com/scl/fi/tua1061dob9ppjafam19h/graph.jpg?rlkey=pmk287josspq6v3sxuk8pygtc&dl=1
- intelcpu_hardware_7155.ico ================= https://www.dropbox.com/scl/fi/svfby9h7xwkylat8ijjhm/intelcpu_hardware_7155.ico?rlkey=o461swa5tyzyct273z7b55hk7&dl=1
- Shell32 Icons Pack ================= https://www.urtech.ca/2022/07/solved-download-list-of-icons-in-shell32-dll/
- ==++"Form1.cs" File 1/2 SourceCode::++==
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Runtime.InteropServices;
- namespace Simple_Drawing_Application
- {
- public partial class Form1 : Form
- {
- private Dictionary<string, object> brushSettings = new Dictionary<string, object>();
- private const string ColorKey = "Color";
- private const string WidthKey = "Width";
- private int storedEraserSize; // Add this line at the class level
- //private Dictionary<string, object> brushSettings = new Dictionary<string, object>();
- //Bards Fixes: (not drawing properly (fixed by ChatGPT) but Form1_Load relocated code + Load Image works normally now Clear still doesn't work but oh well
- private Bitmap drawingLayer;
- private Stack<Bitmap> undoStack = new Stack<Bitmap>();
- private Stack<Bitmap> redoStack = new Stack<Bitmap>();
- //private List<Bitmap> undoList = new List<Bitmap>();
- //private List<Bitmap> redoList = new List<Bitmap>();
- public Point end = new Point();
- public Point start = new Point();
- public Pen p;
- bool draw = false;
- string color;
- Graphics graphics;
- Bitmap bmp;
- bool isEraserActive = false; //(start bard #2 line)
- private SolidBrush brush; // Declare the brush variable //(start bard test #12 line)
- // Add a new variable to store the eraser size
- int eraserSize = 26; //50
- //Image backgroundImage3;
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #1 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private Bitmap brushSilhouette;
- private Bitmap eraserSilhouette;
- private bool canvasDirty = false;
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #1 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #25 Silhouette adding persistent values (disabling Silhouette and persistent code)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- //private string storedPenColor;
- //private float storedPenWidth;
- //private int storedEraserSize;
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #25 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- public Form1()
- {
- InitializeComponent();
- GenerateVariables();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Image backgroundImage3 = Houdini.Properties.Resources.graph;
- //drawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height); //from generatevariables func 4pm 11th Jan 24 temporary
- //Graphics.FromImage(drawingLayer).Clear(Color.Transparent); //from generatevariables func 4pm 11th Jan 24 temporary
- pb_canvas.BackgroundImage = backgroundImage3; // Set as background image
- pb_canvas.BackgroundImageLayout = ImageLayout.Tile;
- // Create the drawing layer only once here
- drawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- if (backgroundImage3 != null)
- {
- int tileWidth = backgroundImage3.Width;
- int tileHeight = backgroundImage3.Height;
- for (int x = 0; x < pb_canvas.Width; x += tileWidth)
- {
- for (int y = 0; y < pb_canvas.Height; y += tileHeight)
- {
- pb_canvas.CreateGraphics().DrawImage(backgroundImage3, new Point(x, y));
- }
- }
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #12 Silhouette (disabling Silhouette and persistent code)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- brushSilhouette = null;
- eraserSilhouette = null;
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #12 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- GenerateVariables();
- }
- private void Form1_Resize(object sender, EventArgs e)
- {
- // Ensure the form doesn't cover the entire screen
- int maxFormWidth = Screen.PrimaryScreen.WorkingArea.Width;
- int maxFormHeight = Screen.PrimaryScreen.WorkingArea.Height;
- this.MaximumSize = new Size(maxFormWidth, maxFormHeight);
- // Adjust the size of the canvas
- pb_canvas.Size = new Size(this.ClientSize.Width, this.ClientSize.Height - menuStrip1.Height);
- //crash fix gpt says to disable below:
- //drawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- //delete if unnecessary
- //original scripts below vv last change to fix Always to Top glitch
- // Adjust the size of pb_canvas to fill the form's client area Formsize= 1362,767
- //pb_canvas.Size = new Size(this.ClientSize.Width, this.ClientSize.Height - menuStrip1.Height);
- // Check if drawingLayer is already created
- if (drawingLayer != null)
- {
- try
- {
- Bitmap newDrawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- using (Graphics g = Graphics.FromImage(newDrawingLayer))
- {
- g.DrawImage(drawingLayer, Point.Empty);
- }
- drawingLayer = newDrawingLayer;
- }
- catch (ArgumentException ex)
- {
- // Handle the exception (optional)
- Console.WriteLine($"Error during resize: {ex.Message}");
- }
- }
- }
- void GenerateVariables()
- {
- // Enable double buffering
- this.DoubleBuffered = true;
- //drawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height); disabled temporarily for Bard 4pm 11th Jan 24
- //backgroundLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height); // Initialize background layer //(start bard #7 line)
- //Graphics.FromImage(drawingLayer).Clear(Color.Transparent); disabled temporarily for Bard 4pm 11th Jan 24
- //start file-path based#1
- //string imagePath = "D:\\Download\\cpp-projekt\\Simple Drawing App\\graph.jpg";
- // Check if the file exists
- //if (File.Exists(imagePath))
- //{
- // Load the image
- //Image backgroundImage2 = Image.FromFile(imagePath);
- //end file-path based#1
- //start embedded-path based#1
- //string imagePath2 = "graph";
- // Check if the file exists "Simple_Drawing_Application.Images.graph.jpg";
- //if (File.Exists(imagePath2))
- //{
- // Load the image from embedded resource
- //Stream imageStream = GetType().Assembly.GetManifestResourceStream(imagePath2);
- //Image backgroundImage3 = Image.FromStream(imageStream);
- //end embedded-path based#1
- //Image backgroundImage3 = Houdini.Properties.Resources.graph; disabled temporarily for Bard 4pm 11th Jan 24
- // Set the background image and enable tiling
- //pb_canvas.BackgroundImage = backgroundImage3; disabled temporarily for Bard 4pm 11th Jan 24
- //pb_canvas.BackgroundImageLayout = ImageLayout.Tile; disabled temporarily for Bard 4pm 11th Jan 24
- //}
- //else
- //{
- //MessageBox.Show("Image file not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- //}
- // Load the tiled background image
- //Stream imageStream = GetType().Assembly.GetManifestResourceStream("pb_canvas.BackgroundImage");
- //Image backgroundImage = Image.FromStream(imageStream);
- // Set the background image to be tiled
- //pb_canvas.BackgroundImage = backgroundImage;
- // Get the friendly name for the color if available, otherwise use the hex value
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- //graphics = pb_canvas.CreateGraphics(); //bard disabled temporarily from func 4pm 11th Jan 24 temp
- // Initialize the pen with a default size
- // You can adjust the color and size as needed
- p = new Pen(Color.Red, 14);
- p.StartCap = p.EndCap = System.Drawing.Drawing2D.LineCap.Round; // Set line cap to round
- p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; // Set line join to round
- comboBox1.Text = "12";
- color = "#FF8040"; //#FF0000 (Red replaced /w pale Orange)
- //txt_color.Text = color;
- // Set the initial background color and display hex color
- // Set your default background color
- //pb_canvas.BackColor = Color.Black; //bard disabled temporarily from func 4pm 11th Jan 24 temp
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- //selectBGToolStripMenuItem.Text = $"Select BG ({ColorToHex(Color.Black)})";
- // Set the tiled background
- //SetTiledBackground();
- // Update the pen color and size dynamically based on the initial values
- UpdatePen();
- // Update font color dynamically
- UpdateFontColor();
- // Attach the Resize event handler
- this.Resize += new EventHandler(Form1_Resize);
- pb_canvas.Paint += new PaintEventHandler(pb_canvas_Paint); //bard disabled temporarily from func 4pm 11th Jan 24 temp
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #2 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- pb_canvas.MouseDown += new MouseEventHandler(pb_canvas_MouseDown); // Added event handler
- pb_canvas.MouseMove += new MouseEventHandler(pb_canvas_MouseMove); // Added event handler
- pb_canvas.MouseUp += new MouseEventHandler(pb_canvas_MouseUp); // Added event handler
- pb_canvas.MouseLeave += new EventHandler(pb_canvas_MouseLeave); // Added event handler
- //pb_canvas.Cursor = Cursors.Cross; // Set cursor to crosshair
- pb_canvas.MouseEnter += new EventHandler(pb_canvas_MouseEnter);
- // Add these lines where you initialize your menu items
- undoToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.Z)));
- redoToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.Y)));
- loadImageToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.O)));
- saveImageToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.S)));
- // Add these lines where you handle other menu items
- undoToolStripMenuItem.Click += new EventHandler(undoToolStripMenuItem_Click);
- redoToolStripMenuItem.Click += new EventHandler(redoToolStripMenuItem_Click);
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #2 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- // Initialize the canvas size
- Form1_Resize(this, EventArgs.Empty);
- // Initialize the Set Font Size menu item text
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({p.Width})";
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #3 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- // Generate brush silhouette
- //brushSilhouette = GenerateBrushSilhouette(p.Width, color);
- // Generate eraser silhouette
- //eraserSilhouette = GenerateEraserSilhouette(eraserSize);
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #3 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- //CreateCanvas();
- }
- private void pb_canvas_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.DrawImage(drawingLayer, Point.Empty);
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #11 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- if (brushSilhouette != null && eraserSilhouette != null)
- {
- // Create a temporary bitmap to draw the silhouette on.
- using (Bitmap tempLayer = new Bitmap(drawingLayer.Width, drawingLayer.Height))
- {
- using (Graphics g = Graphics.FromImage(tempLayer))
- {
- Point cursorPosition = pb_canvas.PointToClient(Cursor.Position);
- // Draw the brush or eraser silhouette on the temporary layer.
- if (isEraserActive)
- {
- g.DrawImage(eraserSilhouette, cursorPosition.X - eraserSize / 2, cursorPosition.Y - eraserSize / 2);
- }
- else
- {
- g.DrawImage(brushSilhouette, cursorPosition.X - (int)p.Width / 2, cursorPosition.Y - (int)p.Width / 2);
- }
- }
- // Draw the temporary layer on top of the existing drawing layer.
- e.Graphics.DrawImage(tempLayer, Point.Empty);
- }
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #11 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #5 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*// Draw brush silhouette
- if (!isEraserActive)
- {
- Point cursorPosition = pb_canvas.PointToClient(Cursor.Position);
- e.Graphics.DrawImage(brushSilhouette, cursorPosition.X - (int)p.Width / 2, cursorPosition.Y - (int)p.Width / 2);
- }
- // Draw eraser silhouette
- if (isEraserActive)
- {
- Point cursorPosition = pb_canvas.PointToClient(Cursor.Position);
- e.Graphics.DrawImage(eraserSilhouette, cursorPosition.X - eraserSize / 2, cursorPosition.Y - eraserSize / 2);
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #5 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #6 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- //e.Graphics.DrawImage(drawingLayer, Point.Empty); // Draw the contents of drawingLayer onto the canvas
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #6 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*if (pb_canvas.BackgroundImage != null)
- {
- e.Graphics.DrawImage(pb_canvas.BackgroundImage, 0, 0, pb_canvas.Width, pb_canvas.Height);
- }*/
- /*if (pb_canvas.BackgroundImage != null)
- {
- e.Graphics.DrawImage(pb_canvas.BackgroundImage, 0, 0, pb_canvas.Width, pb_canvas.Height); // Scale background image to fit canvas
- }
- e.Graphics.DrawImage(drawingLayer, 0, 0);*/
- // Draw the background image if it is set
- /*if (pb_canvas.BackgroundImage != null)
- {
- e.Graphics.DrawImage(pb_canvas.BackgroundImage, Point.Empty);
- }*/
- //(start bard test #8)
- /*e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Enable anti-aliasing
- // Draw the drawing layer on top
- e.Graphics.DrawImage(drawingLayer, Point.Empty);*/
- //(end bard test #8)
- }
- //uncomment if fail
- /*void CreateCanvas()
- {
- bmp = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- using (Graphics g = Graphics.FromImage(bmp))
- {
- // Draw the background image if it is set
- if (pb_canvas.BackgroundImage != null)
- {
- g.DrawImage(pb_canvas.BackgroundImage, Point.Empty);
- }
- }
- pb_canvas.BackgroundImage = bmp;
- pb_canvas.BackgroundImageLayout = ImageLayout.Tile;
- }*/
- //old orig function test4new
- /*void CreateCanvas() {
- bmp = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- graphics = Graphics.FromImage(bmp);
- pb_canvas.BackgroundImage = bmp;
- pb_canvas.BackgroundImageLayout = ImageLayout.None;
- }*/
- private void pb_canvas_MouseDown(object sender, MouseEventArgs e)
- {
- draw = true;
- start = e.Location;
- /*draw = true;
- start = e.Location;
- int size;
- if (comboBox1.Text == "")
- {
- size = 8;
- }
- else
- {
- size = Convert.ToInt32(comboBox1.Text);
- }
- Color newColor = ColorTranslator.FromHtml(color);
- // Update the pen size here
- p = new Pen(newColor, p.Width);
- p.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Round);
- }*/
- }
- private void pb_canvas_MouseMove(object sender, MouseEventArgs e)
- {
- if (draw && e.Button == MouseButtons.Left)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- int radius = eraserSize / 2;
- RectangleF eraseRect = new RectangleF(end.X - radius, end.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddLine(start, end);
- g.DrawPath(p, path);
- }
- }
- }
- start = end;
- UpdateCanvas();
- canvasDirty = true; // Set the canvas dirty flag
- }
- else
- {
- pb_canvas.Invalidate();
- }
- }
- /*if (draw && e.Button == MouseButtons.Left)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- int radius = eraserSize / 2;
- RectangleF eraseRect = new RectangleF(end.X - radius, end.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddLine(start, end);
- g.DrawPath(p, path);
- }
- }
- }
- start = end;
- UpdateCanvas();
- canvasDirty = true; // Set the canvas dirty flag
- }
- else
- {
- pb_canvas.Invalidate();
- }
- }*/
- /*if (draw && e.Button == MouseButtons.Left)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- int radius = eraserSize / 2;
- RectangleF eraseRect = new RectangleF(end.X - radius, end.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddLine(start, end);
- g.DrawPath(p, path);
- }
- }
- }
- start = end;
- UpdateCanvas();
- }
- else
- {
- pb_canvas.Invalidate();
- }
- }*/
- /*if (draw && e.Button == MouseButtons.Left)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- int radius = eraserSize / 2;
- RectangleF eraseRect = new RectangleF(end.X - radius, end.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddLine(start, end);
- g.DrawPath(p, path);
- }
- }
- }
- start = end;
- UpdateCanvas();
- }
- else
- {
- pb_canvas.Invalidate();
- }
- }*/
- /*if (draw && e.Button == MouseButtons.Left)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = eraserSize / 2;
- RectangleF eraseRect = new RectangleF(end.X - radius, end.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddLine(start, end);
- g.DrawPath(p, path);
- }
- }
- }
- start = end;
- pb_canvas.Invalidate();
- }
- else
- {
- pb_canvas.Invalidate();
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #15 Silhouette (disabled) starting anew
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*if (draw && e.Button == MouseButtons.Left)
- //if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = eraserSize / 2;
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- using (SolidBrush brush = new SolidBrush(ColorTranslator.FromHtml(color))) // Update this line
- {
- g.FillEllipse(brush, end.X - (int)p.Width / 2, end.Y - (int)p.Width / 2, p.Width, p.Width);
- }*/
- //g.DrawLine(p, start, end);
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #15 Silhouette (disabled) starting anew
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #7 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #10 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*Graphics g = pb_canvas.CreateGraphics();
- try
- {
- if (!isEraserActive)
- {
- Point cursorPosition = pb_canvas.PointToClient(Cursor.Position);
- g.DrawImage(brushSilhouette, cursorPosition.X - (int)p.Width / 2, cursorPosition.Y - (int)p.Width / 2);
- }
- else
- {
- Point cursorPosition = pb_canvas.PointToClient(Cursor.Position);
- g.DrawImage(eraserSilhouette, cursorPosition.X - eraserSize / 2, cursorPosition.Y - eraserSize / 2);
- }
- }
- finally
- {
- g.Dispose();
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #10 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- //Start #18 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*}
- }
- start = end;
- pb_canvas.Invalidate();
- }
- else
- {
- pb_canvas.Invalidate(); // Add this line to refresh the canvas when not drawing
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #18 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #7 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #8 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer)) // Modify the drawingLayer, not the loaded image
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50;
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- g.DrawLine(p, start, end);
- }
- }
- start = end;
- pb_canvas.Invalidate();
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #8 Silhouette (disabled)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- //start Genius Mode FINAL FINAL FINAL fixes #22 RESAVE()
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(pb_canvas.Image ?? drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50;
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- g.DrawLine(p, start, end);
- }
- }
- start = end;
- pb_canvas.Invalidate();
- }
- }*/
- //end Genius Mode FINAL FINAL FINAL fixes #22 RESAVE()
- //start Genius Mode FINAL FINAL fixes #8 clear()
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- RectangleF eraseRect = new RectangleF(start.X - eraserSize, start.Y - eraserSize, 2 * eraserSize, 2 * eraserSize);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- g.DrawLine(p, start, end);
- }
- }
- start = end;
- pb_canvas.Invalidate();
- }
- }*/
- //end Genius Mode FINAL FINAL fixes #8 clear()
- //start Genius Mode fixes #1
- //ChatGPTs finishing touches
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50;
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent);
- g.ResetClip();
- }
- }
- else
- {
- g.DrawLine(p, start, end);
- }
- }
- start = end;
- pb_canvas.Invalidate();
- }
- }*/
- //end Genius Mode fixes #1
- //Bards fixes
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = pb_canvas.CreateGraphics()) // Create Graphics from the canvas
- //using (Graphics g = Graphics.FromImage(drawingLayer)) disabled temporarily for Bard 4pm 11th Jan 24
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Erase only within the drawing layer's bounds
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50; // Set the radius of your circular clip here
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent); // Clear the drawing layer
- g.ResetClip();
- }
- }*/
- //===================================================================//(start BingAI test FINAL4 #24) Fallback code!
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Erase only within the drawing layer's bounds
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50; // Set the radius of your circular clip here
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent); // Clear the drawing layer
- g.ResetClip();
- }
- }
- else
- {
- g.DrawLine(p, start, end);
- }
- }
- start = end;
- pb_canvas.Invalidate();
- }*/
- //===================================================================//(end BingAI test FINAL4 #23) Fallback code!
- //===================================================================//(start BingAI test #21)
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Erase only within the drawing layer's bounds
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50; // Set the radius of your circular clip here
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent); // Clear the drawing layer
- g.DrawImage(pb_canvas.BackgroundImage, eraseRect, eraseRect, GraphicsUnit.Pixel); // Draw the background image within the clip region
- g.ResetClip();
- }
- }*/
- //===================================================================//(end BingAI test #21)
- //===================================================================(start bard test #19)
- //fully working BingAI Solution!
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Erase only within the drawing layer's bounds
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50; // Set the radius of your circular clip here
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.Clear(Color.Transparent); // Clear the drawing layer
- g.DrawImage(pb_canvas.BackgroundImage, eraseRect, eraseRect, GraphicsUnit.Pixel); // Draw the background image within the clip region
- g.ResetClip();
- }
- }*/
- //===================================================================(end bard test #19)
- //BingAI without Entire Tiled Region Bug
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Erase only within the drawing layer's bounds
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- int radius = 50; // Set the radius of your circular clip here
- RectangleF eraseRect = new RectangleF(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
- using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
- {
- path.AddEllipse(eraseRect);
- g.SetClip(path);
- g.DrawImage(pb_canvas.BackgroundImage, eraseRect, eraseRect, GraphicsUnit.Pixel);
- g.ResetClip();
- }
- }*/
- //===================================================================//(start bard test FINAL #17)
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Calculate clipping rectangle to prevent drawing outside bounds
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- Rectangle eraseRect = new Rectangle(start, new Size(Math.Abs(end.X - start.X) * 3, Math.Abs(end.Y - start.Y) * 3)); // Double the width and height
- //Rectangle eraseRect = new Rectangle(start, new Size(Math.Abs(end.X - start.X), Math.Abs(end.Y - start.Y)));
- Rectangle clipRect = Rectangle.Intersect(drawingBounds, eraseRect);
- // Set clipping region before clearing
- g.SetClip(clipRect);
- g.Clear(Color.Transparent); // Clear within the clipping region
- g.ResetClip(); // Remove clipping region for subsequent operations
- // Erase within the clipping rectangle with transparent color //(start bard test #11 line)
- //g.Clear(Color.Transparent, clipRect);
- }*/
- //===================================================================//(end bard test FINAL #17)
- //start google bard broken deleteme code
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Calculate clipping rectangle considering both axes
- Rectangle eraseRect = new Rectangle(start, new Size(Math.Abs(end.X - start.X), Math.Abs(end.Y - start.Y)));
- // Tile the background image within the erase rectangle
- for (int x = eraseRect.Left; x < eraseRect.Right; x += pb_canvas.BackgroundImage.Width)
- {
- for (int y = eraseRect.Top; y < eraseRect.Bottom; y += pb_canvas.BackgroundImage.Height)
- {
- g.DrawImage(pb_canvas.BackgroundImage, x, y);
- }
- }
- }*/
- //end google bard broken deleteme code
- //(start bard test #10)
- /*if (draw)
- {
- end = e.Location;
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Calculate clipping rectangle to ensure erasing within bounds
- Rectangle drawingBounds = new Rectangle(0, 0, drawingLayer.Width, drawingLayer.Height);
- Rectangle eraseRect = new Rectangle(start, new Size(Math.Abs(end.X - start.X), Math.Abs(end.Y - start.Y)));
- Rectangle clipRect = Rectangle.Intersect(drawingBounds, eraseRect);
- // Only erase if the clipping rectangle has non-zero dimensions
- if (clipRect.Width > 0 && clipRect.Height > 0)
- {
- g.DrawImage(pb_canvas.BackgroundImage, clipRect, clipRect, GraphicsUnit.Pixel);
- }
- }*/
- //(end bard test #10)
- //(start bard test #9)
- /*g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- if (isEraserActive)
- {
- // Erase by copying pixels from the background image
- if (pb_canvas.BackgroundImage != null)
- {
- g.DrawImage(pb_canvas.BackgroundImage, start.X, start.Y, end.X - start.X, end.Y - start.Y);
- }
- }
- else
- {
- g.DrawLine(p, start, end);
- }
- }
- start = end;
- pb_canvas.Invalidate();
- }
- }*/
- //(end bard test #9)
- //(start bard #6)
- /*//if (e.Button == MouseButtons.Left)
- //{
- end = e.Location;
- // Use CreateGraphics to draw on the PictureBox
- // Instead of creating a new Graphics object, use the one provided in the PaintEventArgs
- using (Graphics g = Graphics.FromImage(drawingLayer))
- //using (Graphics g = pb_canvas.CreateGraphics())
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Enable anti-aliasing for drawing layer
- g.DrawLine(p, start, end);
- }
- //graphics.DrawLine(p, start, end);
- start = end;
- pb_canvas.Invalidate();
- }//*(end bard #6)
- }
- //}
- /*private void SetTiledBackground()
- {
- try
- {
- //string filePath = @"D:\Download\cpp-projekt\Simple Drawing App\bin\Debug\graph9.gif";
- string resourceName = "Simple_Drawing_Application.graph9.gif";
- // Replace "YourNamespace" with the actual namespace where the GIF is stored
- //if (File.Exists(filePath))
- using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(resourceName))
- {
- if (stream != null)
- {
- // Load the GIF from the stream
- Image tiledBackground = Image.FromStream(stream);
- // Set the BackgroundImage property of pb_canvas
- pb_canvas.BackgroundImage = tiledBackground;
- // Set the BackgroundImageLayout property to Tile to tile the image
- pb_canvas.BackgroundImageLayout = ImageLayout.Tile;
- }
- else
- {
- MessageBox.Show("Failed to get the resource stream.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error setting tiled background: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }*/
- /*{
- // Load the GIF from the file
- Image tiledBackground = Image.FromFile(filePath);
- // Set the BackgroundImage property of pb_canvas
- pb_canvas.BackgroundImage = tiledBackground;
- // Set the BackgroundImageLayout property to Tile to tile the image
- pb_canvas.BackgroundImageLayout = ImageLayout.Tile;
- }
- else
- {
- MessageBox.Show("The specified file does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error setting tiled background: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }*/
- /*{
- if (stream != null)
- {
- // Load the GIF from the stream
- Image tiledBackground = Image.FromStream(stream);
- // Set the BackgroundImage property of pb_canvas
- pb_canvas.BackgroundImage = tiledBackground;
- // Set the BackgroundImageLayout property to Tile to tile the image
- pb_canvas.BackgroundImageLayout = ImageLayout.Tile;
- }
- else
- {
- MessageBox.Show("Failed to get the resource stream.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error setting tiled background: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #4 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private Bitmap GenerateBrushSilhouette(float width, string color)
- {
- Bitmap brushSilhouette = new Bitmap((int)width, (int)width);
- using (Graphics g = Graphics.FromImage(brushSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- Color fillColor = ColorTranslator.FromHtml(color);
- using (Brush brush = new SolidBrush(fillColor))
- {
- g.FillEllipse(brush, 0, 0, width, width);
- }
- // Ensure the bitmap has an alpha channel for transparency
- brushSilhouette.MakeTransparent();
- }
- return brushSilhouette;
- }
- /*Bitmap brushSilhouette = new Bitmap((int)width, (int)width);
- using (Graphics g = Graphics.FromImage(brushSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(ColorTranslator.FromHtml(color)))
- {
- g.FillEllipse(brush, 0, 0, width, width);
- }
- }
- return brushSilhouette;
- }*/
- /*Bitmap brushSilhouette = new Bitmap((int)width, (int)width, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- using (Graphics g = Graphics.FromImage(brushSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(ColorTranslator.FromHtml(color)))
- {
- g.FillEllipse(brush, 0, 0, width, width);
- }
- }
- return brushSilhouette;
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #39 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*Bitmap brushSilhouette = new Bitmap((int)width, (int)width);
- using (Graphics g = Graphics.FromImage(brushSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(ColorTranslator.FromHtml(color)))
- {
- g.FillEllipse(brush, 0, 0, width, width);
- }
- }
- return brushSilhouette;
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #39 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #37 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*int silhouetteSize = (int)width;
- if (silhouetteSize <= 0)
- {
- return null; // Avoid creating invalid bitmaps
- }
- Bitmap brushSilhouette = new Bitmap(silhouetteSize, silhouetteSize);
- using (Graphics g = Graphics.FromImage(brushSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(ColorTranslator.FromHtml(color)))
- {
- g.FillEllipse(brush, 0, 0, silhouetteSize, silhouetteSize);
- }
- }
- return brushSilhouette;
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #37 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #27 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*Bitmap brushSilhouette = new Bitmap((int)width, (int)width);
- using (Graphics g = Graphics.FromImage(brushSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(ColorTranslator.FromHtml(color)))
- {
- g.FillEllipse(brush, 0, 0, width, width);
- }
- }
- return brushSilhouette;
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #27 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private Bitmap GenerateEraserSilhouette(int size)
- {
- Bitmap eraserSilhouette = new Bitmap(size, size);
- using (Graphics g = Graphics.FromImage(eraserSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(Color.Black))
- {
- g.FillEllipse(brush, 0, 0, size, size);
- }
- }
- return eraserSilhouette;
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #38 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*int silhouetteSize = size;
- if (silhouetteSize <= 0)
- {
- return null; // Avoid creating invalid bitmaps
- }
- Bitmap eraserSilhouette = new Bitmap(silhouetteSize, silhouetteSize);
- using (Graphics g = Graphics.FromImage(eraserSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(Color.Black))
- {
- g.FillEllipse(brush, 0, 0, silhouetteSize, silhouetteSize);
- }
- using (Pen pen = new Pen(Color.Black, 2))
- {
- g.DrawEllipse(pen, 0, 0, silhouetteSize, silhouetteSize);
- }
- }
- return eraserSilhouette;
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #38 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #27 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*Bitmap eraserSilhouette = new Bitmap(size, size);
- using (Graphics g = Graphics.FromImage(eraserSilhouette))
- {
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- using (Brush brush = new SolidBrush(Color.Black))
- {
- g.FillEllipse(brush, 0, 0, size, size);
- }
- using (Pen pen = new Pen(Color.Black, 2))
- {
- g.DrawEllipse(pen, 0, 0, size, size);
- }
- }
- return eraserSilhouette;
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #27 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #4 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- void UpdatePen()
- {
- // Update the pen color and size based on the current values
- p.Color = ColorTranslator.FromHtml(color);
- //p.Width = Convert.ToInt32(comboBox1.Text);
- GenerateSilhouettes();
- // Update the Set Font Size menu item text
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({p.Width})";
- }
- private void pb_canvas_MouseUp(object sender, MouseEventArgs e)
- {
- draw = false;
- PushToUndoStackIfNeeded();
- }
- private void PushToUndoStack()
- {
- undoStack.Push(new Bitmap(drawingLayer));
- redoStack.Clear();
- }
- private void PushToUndoStackIfNeeded()
- {
- if (canvasDirty)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- redoStack.Clear();
- canvasDirty = false; // Reset the canvas dirty flag
- }
- }
- private void Undo()
- {
- if (undoStack.Count > 0)
- {
- redoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- }
- private void Redo()
- {
- if (redoStack.Count > 0)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- else if (undoStack.Count > 0)
- {
- redoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- }
- //this is in perfect working condition (undo()) but gpt has a fix for redo that requires changing this
- /*private void Undo()
- {
- PushToUndoStackIfNeeded();
- if (undoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- else if (redoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- }
- private void Redo()
- {
- if (redoStack.Count > 0)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- else
- {
- // If redoStack is empty, check if undoStack has items
- if (undoStack.Count > 0)
- {
- redoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- }
- }*/
- //bards broken fix
- /*private void Redo()
- {
- if (redoStack.Count > 0)
- {
- // **Ensure consistent state for Redo**
- drawingLayer.Dispose(); // Dispose of current drawing layer before loading a new one
- drawingLayer = new Bitmap(redoStack.Pop());
- undoStack.Push(new Bitmap(drawingLayer)); // Add the reverted state to undoStack
- UpdateCanvas();
- }
- }*/
- //redo broken this is original below, undo working
- /*private void Redo()
- {
- if (redoStack.Count > 0)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- redoStack.Clear(); // Clear the redo stack after redoing an action
- UpdateCanvas();
- }
- }*/
- /*private void Redo()
- {
- if (redoStack.Count > 0)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- }*/
- /*private void Redo()
- {
- if (redoStack.Count > 0)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- else if (undoStack.Count > 0)
- {
- redoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- }*/
- /*private void Redo()
- {
- PushToUndoStackIfNeeded();
- if (redoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- else if (undoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- }*/
- /*private void Undo()
- {
- if (canvasDirty)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- redoStack.Clear();
- canvasDirty = false; // Reset the canvas dirty flag
- }
- if (undoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- else if (redoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- }
- private void Redo()
- {
- if (canvasDirty)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- redoStack.Clear();
- canvasDirty = false; // Reset the canvas dirty flag
- }
- if (redoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- else if (undoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- }*/
- /*private void Undo()
- {
- if (undoStack.Count > 0)
- {
- redoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- else if (redoStack.Count > 0)
- {
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- }
- private void Redo()
- {
- if (redoStack.Count > 0)
- {
- undoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(redoStack.Pop());
- UpdateCanvas();
- }
- else if (undoStack.Count > 0)
- {
- redoStack.Push(new Bitmap(drawingLayer));
- drawingLayer.Dispose();
- drawingLayer = new Bitmap(undoStack.Pop());
- UpdateCanvas();
- }
- }*/
- private void UpdateCanvas()
- {
- pb_canvas.Invalidate();
- }
- private void undoToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Undo();
- }
- private void redoToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Redo();
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.P)
- {
- ActivatePaintbrush();
- }
- else if (e.KeyCode == Keys.E)
- {
- ActivateEraser();
- }
- else if (e.KeyCode == Keys.C)
- {
- ClearCanvas();
- }
- // Check if the user pressed the '+' or '-' key
- else if (e.KeyCode == Keys.Oemplus || e.KeyCode == Keys.Add)
- {
- // Increase the paintbrush size by 1
- IncreasePaintbrushSize();
- }
- else if (e.KeyCode == Keys.OemMinus || e.KeyCode == Keys.Subtract)
- {
- // Decrease the paintbrush size by 1
- DecreasePaintbrushSize();
- }
- }
- private void clearToolStripMenuItem_Click(object sender, EventArgs e)
- {
- ClearCanvas();
- }
- //This is GPTs final attempt (fail)
- /*DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (result == DialogResult.Yes)
- {
- drawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- pb_canvas.BackgroundImage = null; // Clear background image
- pb_canvas.Invalidate();
- }
- }*/
- //ChatGPTs Final Attempt (Bing below Failed don't use below)
- /*// Display a confirmation dialog
- DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- // Check the user's response
- if (result == DialogResult.Yes)
- {
- // Clear the drawing layer
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- // Clear the PictureBox's Image
- pb_canvas.Image = null;
- // Refresh the PictureBox to reflect the changes
- pb_canvas.Invalidate();
- }
- // If the user clicks "No" or closes the dialog, do nothing
- }*/
- //Bings Final Attempt (below is not original)
- /*// Display a confirmation dialog
- DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- // Check the user's response
- if (result == DialogResult.Yes)
- {
- // Clear the drawing layer
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- // Clear the PictureBox's Image
- //pb_canvas.Image = null;
- // Refresh the PictureBox to reflect the changes
- pb_canvas.Invalidate();
- }
- // If the user clicks "No" or closes the dialog, do nothing
- }*/
- //start Genius Mode FINAL FINAL FINAL fixes #21 RESAVE()
- /*DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (result == DialogResult.Yes)
- {
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- pb_canvas.Image = null; // Clear the Image property instead of the BackgroundImage
- pb_canvas.Invalidate();
- }
- }*/
- //end Genius Mode FINAL FINAL FINAL fixes #21 RESAVE()
- //start Genius Mode FINAL fixes #6 clear()
- /*//BingAI Final Test for Load Clear
- // Display a confirmation dialog
- DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (result == DialogResult.Yes)
- {
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- pb_canvas.BackgroundImage = null; // Clear the background image as well
- pb_canvas.Invalidate();
- }
- // If the user clicks "No" or closes the dialog, do nothing
- }*/
- //end Genius Mode FINAL fixes #6 clear()
- //===================================================================//(start BingAI test FINAL4 #23) Fallback code!
- /*// Display a confirmation dialog
- DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- // Check the user's response
- if (result == DialogResult.Yes)
- {
- // Clear the drawing layer
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- // Refresh the PictureBox to reflect the changes
- pb_canvas.Invalidate();
- }
- // If the user clicks "No" or closes the dialog, do nothing
- }*/
- //===================================================================//(start BingAI test FINAL4 #23) Fallback code!
- //===================================================================//(start BingAI test FINAL3 #21)
- /*// Display a confirmation dialog
- DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- // Check the user's response
- if (result == DialogResult.Yes)
- {
- // Clear the drawing layer
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- // Clear the PictureBox background image
- pb_canvas.Image = null;
- pb_canvas.Invalidate();
- //pb_canvas.BackgroundImage = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- // Clear the drawing window
- //pb_canvas.Invalidate();
- //CreateCanvas();
- }
- // If the user clicks "No" or closes the dialog, do nothing
- }*/
- //===================================================================//(end BingAI test FINAL3 #21)
- private void ClearCanvas()
- {
- DialogResult result = MessageBox.Show("Are you sure you want to clear the drawing window?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (result == DialogResult.Yes)
- {
- drawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height); // Create a new drawingLayer with the same size as the PictureBox
- pb_canvas.Image = null; // Clear the Image property
- pb_canvas.Invalidate();
- }
- }
- private void UpdateFontColor()
- {
- // (for English colornames)
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- // Update the font color text dynamically in the menu bar (orig)
- //selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- }
- private void SetBackgroundColor()
- {
- // Display the ColorDialog to let the user choose a background color
- ColorDialog colorDialog = new ColorDialog();
- if (colorDialog.ShowDialog() == DialogResult.OK)
- {
- // Set the background color of pb_canvas
- pb_canvas.BackColor = colorDialog.Color;
- //delete this if fail (not hex)
- // Get the friendly name for the color if available, otherwise use the hex value
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- //delete this if fail (not hex)
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- // Display the hex color in the menu item dynamically (orig)
- //selectBGToolStripMenuItem.Text = $"Select BG ({ColorToHex(colorDialog.Color)})";
- }
- }
- // Helper method to convert Color to hex string
- private string ColorToHex(Color color)
- {
- return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
- }
- private void IncreasePaintbrushSize()
- {
- if (isEraserActive)
- {
- eraserSize += 1;
- setFontSizeToolStripMenuItem.Text = $"Set Size ({eraserSize})";
- GenerateSilhouettes(); //added 15 minutes ago ++--
- }
- else
- {
- float newSize = p.Width + 1;
- p.Width = newSize;
- setFontSizeToolStripMenuItem.Text = $"Set Size ({newSize})";
- GenerateSilhouettes(); //added 15 minutes ago ++--
- }
- }
- //start Genius Mode fixes #3 increasepaintsize()
- /*// Increase the paintbrush size by 1
- float newSize = p.Width + 1;
- // Update the pen size
- p.Width = newSize;
- // Update the menu item text with the new size
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({newSize})";
- }*/
- //end Genius Mode fixes #3 increasepaintsize()
- private void DecreasePaintbrushSize()
- {
- if (isEraserActive)
- {
- if (eraserSize > 1)
- {
- eraserSize -= 1;
- setFontSizeToolStripMenuItem.Text = $"Set Size ({eraserSize})";
- GenerateSilhouettes(); //added 15 minutes ago ++--
- }
- }
- else
- {
- if (p.Width > 1)
- {
- float newSize = p.Width - 1;
- p.Width = newSize;
- setFontSizeToolStripMenuItem.Text = $"Set Size ({newSize})";
- GenerateSilhouettes(); //added 15 minutes ago ++--
- }
- }
- }
- //start Genius Mode fixes #4 decreasepaintsize()
- /*// Ensure the size does not go below 1
- if (p.Width > 1)
- {
- // Decrease the paintbrush size by 1
- float newSize = p.Width - 1;
- // Update the pen size
- p.Width = newSize;
- // Update the menu item text with the new size
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({newSize})";
- }
- }*/
- //end Genius Mode fixes #4 decreasepaintsize()
- private void quitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void paintbrushToolStripMenuItem_Click(object sender, EventArgs e)
- {
- ActivatePaintbrush();
- }
- private void ActivatePaintbrush()
- {
- brushSettings.Clear();
- isEraserActive = false;
- //color = "#FF0000";
- ///p.Width = 14; //12
- UpdatePenColor();
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({p.Width})";
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #40 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*StoreCurrentToolSettings(); //(disabling Silhouette and persistent code)
- isEraserActive = false;
- color = "#FF0000";
- p.Width = 12;
- UpdatePenColor();
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({p.Width})";
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #40 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #22 Silhouette (adding persistent settings)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*isEraserActive = false;
- color = "#FF0000";
- p.Width = 12;
- UpdatePenColor();
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({p.Width})";
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #22 Silhouette (adding persistent settings)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #16 Silhouette (disabled) starting anew
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*isEraserActive = false; // Allow switching back to Paintbrush
- color = "#FF0000";
- p.Width = 12;
- UpdatePen();
- GenerateSilhouettes(); //added 15 minutes ago
- //comboBox1.Text = "12";
- //txt_color.Text = color;
- // Get the friendly name for the color if available, otherwise use the hex value
- //string friendlyColorName = GetFriendlyColorName(pb_canvas.BackColor);
- // Get the friendly name for the color if available, otherwise use the hex value
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- // Update other menu items dynamically
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({p.Width})";
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- //selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(ColorTranslator.FromHtml(color))})";
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #16 Silhouette (disabled) starting anew
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private void eraserToolStripMenuItem_Click(object sender, EventArgs e)
- {
- ActivateEraser();
- }
- private void ActivateEraser()
- {
- brushSettings.Clear();
- isEraserActive = true;
- brush = new SolidBrush(Color.Transparent);
- UpdatePenColor();
- GenerateSilhouettes();
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({eraserSize})";
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #41 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*StoreCurrentToolSettings(); //(disabling Silhouette and persistent code)
- isEraserActive = true;
- brush = new SolidBrush(Color.Transparent);
- UpdatePenColor();
- GenerateSilhouettes(); //added 15 minutes ago ++--
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({eraserSize})";
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #41 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #23 Silhouette (adding persistent settings)
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*isEraserActive = true; //(start bard #3 line)
- //color = "#00FFFFFF"; //(start bard #4 line) "#000000"
- brush = new SolidBrush(Color.Transparent); // Use SolidBrush with Transparent color //(start bard test #13 line)
- //p.Width = 60;
- UpdatePen();
- GenerateSilhouettes(); //added 15 minutes ago
- //comboBox1.Text = "17";
- //txt_color.Text = color;
- // Get the friendly name for the color if available, otherwise use the hex value
- //string friendlyColorName = GetFriendlyColorName(pb_canvas.BackColor);
- // Get the friendly name for the color if available, otherwise use the hex value
- string friendlyColorName = Color.FromName(pb_canvas.BackColor.Name).IsKnownColor
- ? pb_canvas.BackColor.Name
- : $"#{pb_canvas.BackColor.R:X2}{pb_canvas.BackColor.G:X2}{pb_canvas.BackColor.B:X2}";
- // Update other menu items dynamically orig: $"Set Font Size ({p.Width})";
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({eraserSize})";
- selectBGToolStripMenuItem.Text = $"Select Background ({friendlyColorName})";
- selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(color)})";
- //selectColorToolStripMenuItem.Text = $"Select Color ({GetFriendlyColorName(ColorTranslator.FromHtml(color))})";
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #23 Silhouette adding persistent settings
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- //private Dictionary<string, object> brushSettings = new Dictionary<string, object>();
- private void StoreCurrentToolSettings()
- {
- //brushSettings["Color"] = isEraserActive ? Color.Transparent : color;
- brushSettings["Color"] = isEraserActive ? (object)Color.Transparent : (object)color;
- brushSettings["Width"] = isEraserActive ? (object)eraserSize : (object)p.Width;
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #39 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*if (!isEraserActive)
- {
- storedPenColor = color;
- storedPenWidth = p.Width;
- }
- else
- {
- storedEraserSize = eraserSize;
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #39 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private void RestorePreviousToolSettings()
- {
- color = brushSettings.ContainsKey("Color") ? (string)brushSettings["Color"] : "#FF0000";
- p.Width = brushSettings.ContainsKey("Width") ? (float)brushSettings["Width"] : 12f;
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #40 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*if (!isEraserActive)
- {
- color = storedPenColor;
- p.Width = storedPenWidth;
- }
- else
- {
- eraserSize = storedEraserSize;
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #40 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private void loadImageToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string filePath = openFileDialog.FileName;
- try
- {
- Image loadedImage = Image.FromFile(filePath);
- pb_canvas.Image = new Bitmap(loadedImage, pb_canvas.Size); // Resize the loaded image to match the PictureBox size
- drawingLayer = new Bitmap(pb_canvas.Image.Width, pb_canvas.Image.Height); // Create a new drawingLayer with the same size as the PictureBox
- using (Graphics g = Graphics.FromImage(drawingLayer))
- {
- g.DrawImage(loadedImage, Point.Empty); // Draw the loaded image onto the drawingLayer
- }
- pb_canvas.Invalidate();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- //start Genius Mode FINAL FINAL FINAL fixes #20 RESAVE()
- /*OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string filePath = openFileDialog.FileName;
- try
- {
- pb_canvas.Image = Image.FromFile(filePath); // Load the image onto the PictureBox's Image property
- drawingLayer = new Bitmap(pb_canvas.Image); // Update the drawingLayer to match the loaded image
- pb_canvas.Invalidate();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //end Genius Mode FINAL FINAL FINAL fixes #20 RESAVE()
- /*//This is GPTs final attempt (fail)
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string filePath = openFileDialog.FileName;
- try
- {
- drawingLayer = new Bitmap(pb_canvas.Width, pb_canvas.Height); // Reset drawing layer
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- pb_canvas.BackgroundImage = Image.FromFile(filePath);
- pb_canvas.BackgroundImageLayout = ImageLayout.Stretch; // Adjust background image layout
- pb_canvas.Image = null;
- pb_canvas.Invalidate();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //ChatGPTs Final Attempt (Bing below Failed don't use below)
- /*OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string filePath = openFileDialog.FileName;
- try
- {
- // Clear the drawing layer
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- pb_canvas.Invalidate();
- // Load the selected image into the PictureBox's Image
- pb_canvas.Image = Image.FromFile(filePath);
- // Set the PictureBox's BackgroundImageLayout to Zoom
- pb_canvas.BackgroundImageLayout = ImageLayout.Zoom;
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //Bings Final Attempt (below is not original)
- //start Genius Mode FINAL FINAL fixes #9 load()
- /*OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string filePath = openFileDialog.FileName;
- try
- {
- pb_canvas.Image = Image.FromFile(filePath); // Load the image onto the PictureBox's Image property
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent); // Clear the drawingLayer
- pb_canvas.Invalidate();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //end Genius Mode FINAL FINAL fixes #9 load()
- //start Genius Mode FINAL fixes #7 loadimage()
- /*OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string filePath = openFileDialog.FileName;
- try
- {
- pb_canvas.Image = Image.FromFile(filePath);
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- pb_canvas.BackgroundImage = null; // Clear previous background if any
- pb_canvas.Invalidate();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //end Genius Mode FINAL fixes #7 loadimage()
- //===================================================================//(start BingAI test FINAL #18)
- /*OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string filePath = openFileDialog.FileName;
- try
- {
- // Clear the drawing layer
- Graphics.FromImage(drawingLayer).Clear(Color.Transparent);
- pb_canvas.Invalidate();
- // Load the selected image into the PictureBox
- pb_canvas.Image = Image.FromFile(filePath);
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //===================================================================//(end BingAI test FINAL #18)
- private void saveImageToolStripMenuItem_Click(object sender, EventArgs e)
- {
- SaveFileDialog s = new SaveFileDialog();
- s.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- try
- {
- Bitmap mergedImage = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- using (Graphics g = Graphics.FromImage(mergedImage))
- {
- if (pb_canvas.Image != null)
- {
- g.DrawImage(pb_canvas.Image, Point.Empty); // Draw the loaded image (if any)
- }
- g.DrawImage(drawingLayer, Point.Empty); // Draw the drawingLayer
- }
- if (s.FileName.Contains(".jpg"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- else if (s.FileName.Contains(".png"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (s.FileName.Contains(".bmp"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error saving image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- //start Genius Mode FINAL FINAL FINAL fixes #23 RESAVE()
- /*SaveFileDialog s = new SaveFileDialog();
- s.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- try
- {
- Bitmap mergedImage = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- using (Graphics g = Graphics.FromImage(mergedImage))
- {
- g.DrawImage(pb_canvas.Image ?? drawingLayer, Point.Empty);
- }
- if (s.FileName.Contains(".jpg"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- else if (s.FileName.Contains(".png"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (s.FileName.Contains(".bmp"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error saving image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //end Genius Mode FINAL FINAL FINAL fixes #23 RESAVE()
- //start Genius Mode FINAL FINAL fixes #10 save()
- /*SaveFileDialog s = new SaveFileDialog();
- s.Filter = "Png files|*.png|jpeg files|*.jpg|bitmaps|*.bmp";
- if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- try
- {
- // Create a new bitmap to hold the merged image
- Bitmap mergedImage = new Bitmap(pb_canvas.Width, pb_canvas.Height);
- // Create a graphics object from the merged image
- using (Graphics g = Graphics.FromImage(mergedImage))
- {
- // Draw the background image repeatedly to fill the canvas
- for (int x = 0; x < pb_canvas.Width; x += pb_canvas.BackgroundImage.Width)
- {
- for (int y = 0; y < pb_canvas.Height; y += pb_canvas.BackgroundImage.Height)
- {
- g.DrawImage(pb_canvas.BackgroundImage, new Point(x, y));
- }
- }
- // Draw the drawing layer
- g.DrawImage(drawingLayer, Point.Empty);
- }
- // Save the merged image
- if (s.FileName.Contains(".jpg"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- else if (s.FileName.Contains(".png"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (s.FileName.Contains(".bmp"))
- {
- mergedImage.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error saving image: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }*/
- //end Genius Mode FINAL FINAL fixes #10 save()
- //old fallbackcode return if unsatisfied
- /*{
- SaveFileDialog s = new SaveFileDialog();
- s.Filter = "Png files| *.png|jpeg files| *.jpg|bitmaps | *.bmp";
- if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (File.Exists(s.FileName))
- {
- File.Delete(s.FileName);
- }
- if (s.FileName.Contains(".jpg"))
- {
- bmp.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- else if (s.FileName.Contains(".png"))
- {
- bmp.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (s.FileName.Contains(".bmp"))
- {
- bmp.Save(s.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
- }
- }
- }*/
- private void selectColorToolStripMenuItem_Click(object sender, EventArgs e)
- {
- ColorDialog cd = new ColorDialog();
- if (cd.ShowDialog() == DialogResult.OK)
- {
- color = "#" + (cd.Color.ToArgb() & 0x00FFFFFF).ToString("X6");
- UpdatePenColor();
- }
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #15 Silhouette (disabled) starting anew
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*ColorDialog cd = new ColorDialog();
- if (cd.ShowDialog() == DialogResult.OK)
- {
- color = "#" + (cd.Color.ToArgb() & 0x00FFFFFF).ToString("X6");
- //txt_color.Text = color;
- // Update font color dynamically
- UpdateFontColor();
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #15 Silhouette (disabled) starting anew
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private void UpdatePenColor()
- {
- p.Color = ColorTranslator.FromHtml(color);
- UpdateFontColor();
- GenerateSilhouettes(); //(disabling Silhouette and persistent code) ++--
- }
- private void setFontSizeToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (p == null)
- {
- p = new Pen(Color.Black, 1);
- }
- using (Form inputForm = new Form())
- {
- inputForm.Text = "Set Size";
- Label promptLabel = new Label();
- promptLabel.Text = isEraserActive ? "Enter new eraser size:" : "Enter new font size:";
- promptLabel.Location = new Point(10, 10);
- inputForm.Controls.Add(promptLabel);
- TextBox inputBox = new TextBox();
- inputBox.Location = new Point(10, 30);
- inputForm.Controls.Add(inputBox);
- Button okButton = new Button();
- okButton.Text = "OK";
- okButton.DialogResult = DialogResult.OK;
- okButton.Location = new Point(10, 60);
- inputForm.Controls.Add(okButton);
- if (inputForm.ShowDialog() == DialogResult.OK)
- {
- if (int.TryParse(inputBox.Text, out int newSize))
- {
- if (isEraserActive)
- {
- eraserSize = newSize;
- }
- else
- {
- p.Width = newSize;
- }
- GenerateSilhouettes(); //added 15 minutes ago ++--
- setFontSizeToolStripMenuItem.Text = $"Set Size ({newSize})";
- }
- else
- {
- MessageBox.Show("Invalid input. Please enter a valid number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- //start Genius Mode fixes #2
- /*if (p == null)
- {
- // Initialize the pen with default values if not already initialized
- p = new Pen(Color.Black, 1); // You can adjust the color and size as needed
- }
- // Display the current pen size in the menu dynamically
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({p.Width})";
- // Create a form with a TextBox for user input
- using (Form inputForm = new Form())
- {
- inputForm.Text = "Set Font Size";
- Label promptLabel = new Label();
- promptLabel.Text = "Enter new font size:";
- promptLabel.Location = new Point(10, 10);
- inputForm.Controls.Add(promptLabel);
- TextBox inputBox = new TextBox();
- inputBox.Location = new Point(10, 30);
- inputForm.Controls.Add(inputBox);
- Button okButton = new Button();
- okButton.Text = "OK";
- okButton.DialogResult = DialogResult.OK;
- okButton.Location = new Point(10, 60);
- inputForm.Controls.Add(okButton);
- // Show the form and get user input
- if (inputForm.ShowDialog() == DialogResult.OK)
- {
- // Check if the user entered a valid number
- if (float.TryParse(inputBox.Text, out float newSize))
- {
- // Update the pen size
- p.Width = newSize;
- // Update the menu item text with the new size
- setFontSizeToolStripMenuItem.Text = $"Set Font Size ({newSize})";
- }
- else
- {
- // Display an error message if the input is not a valid number
- MessageBox.Show("Invalid input. Please enter a valid number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }*/
- //end Genius Mode fixes #2
- private void selectBGToolStripMenuItem_Click(object sender, EventArgs e)
- {
- // Call the method to change the background color
- SetBackgroundColor();
- }
- private string GetFriendlyColorName(string hexColor)
- {
- Color color = ColorTranslator.FromHtml(hexColor);
- // Check if the color is one of the known colors
- foreach (KnownColor knownColor in Enum.GetValues(typeof(KnownColor)))
- {
- Color knownColorObj = Color.FromKnownColor(knownColor);
- if (knownColorObj.ToArgb() == color.ToArgb())
- {
- return knownColorObj.Name;
- }
- }
- // If not a known color, return the original hex color
- return hexColor;
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #9 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- private void pb_canvas_MouseLeave(object sender, EventArgs e)
- {
- pb_canvas.Invalidate();
- Cursor.Show();
- // Reset the cursor to default when leaving the drawing area
- pb_canvas.Cursor = Cursors.Default;
- }
- // Moved silhouette generation to a separate method for clarity
- private void GenerateSilhouettes()
- {
- brushSilhouette = GenerateBrushSilhouette(p.Width, color);
- eraserSilhouette = GenerateEraserSilhouette(eraserSize);
- }
- private void pb_canvas_MouseEnter(object sender, EventArgs e)
- {
- //RestorePreviousToolSettings();
- GenerateSilhouettes(); //++--
- Cursor.Hide();
- //hiding this block to test for Silhouette bugs
- /*if (!isEraserActive && brushSilhouette != null)
- {
- int xHotSpot = brushSilhouette.Width / 2;
- int yHotSpot = brushSilhouette.Height / 2;
- pb_canvas.Cursor = CreateCursor(brushSilhouette, xHotSpot, yHotSpot);
- }
- else if (isEraserActive && eraserSilhouette != null)
- {
- int xHotSpot = eraserSilhouette.Width / 2;
- int yHotSpot = eraserSilhouette.Height / 2;
- pb_canvas.Cursor = CreateCursor(eraserSilhouette, xHotSpot, yHotSpot);
- }*/
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- // Display a confirmation message box
- DialogResult result = MessageBox.Show("Are you sure you want to exit?", "Confirm Exit", MessageBoxButtons.YesNo);
- // If the user chooses No, cancel the closing process
- if (result == DialogResult.No)
- {
- e.Cancel = true;
- }
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #35 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*RestorePreviousToolSettings();
- GenerateSilhouettes();
- Cursor.Hide();
- if (!isEraserActive && brushSilhouette != null)
- {
- int xHotSpot = brushSilhouette.Width / 2;
- int yHotSpot = brushSilhouette.Height / 2;
- pb_canvas.Cursor = CreateCursor(brushSilhouette, xHotSpot, yHotSpot);
- }
- else if (isEraserActive && eraserSilhouette != null)
- {
- int xHotSpot = eraserSilhouette.Width / 2;
- int yHotSpot = eraserSilhouette.Height / 2;
- pb_canvas.Cursor = CreateCursor(eraserSilhouette, xHotSpot, yHotSpot);
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #35 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #31 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*RestorePreviousToolSettings();
- GenerateSilhouettes();
- Cursor.Hide();
- if (!isEraserActive && brushSilhouette != null)
- {
- pb_canvas.Cursor = CreateCursor(brushSilhouette, brushSilhouette.Width / 2, brushSilhouette.Height / 2);
- }
- else if (isEraserActive && eraserSilhouette != null)
- {
- pb_canvas.Cursor = CreateCursor(eraserSilhouette, eraserSilhouette.Width / 2, eraserSilhouette.Height / 2);
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #31 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #29 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*RestorePreviousToolSettings();
- GenerateSilhouettes();
- Cursor.Hide();
- if (!isEraserActive)
- {
- pb_canvas.Cursor = CreateCursor(brushSilhouette, (int)p.Width / 2, (int)p.Width / 2);
- }
- else
- {
- pb_canvas.Cursor = CreateCursor(eraserSilhouette, eraserSize / 2, eraserSize / 2);
- }
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #29 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #24 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*GenerateSilhouettes();
- Cursor.Hide();
- //delete these "if else" if unnecessary
- // Set the cursor to the brush silhouette when not using the eraser
- if (!isEraserActive)
- {
- pb_canvas.Cursor = CreateCursor(brushSilhouette, (int)p.Width / 2, (int)p.Width / 2);
- }
- // Set the cursor to the eraser silhouette when using the eraser
- else
- {
- pb_canvas.Cursor = CreateCursor(eraserSilhouette, eraserSize / 2, eraserSize / 2);
- }
- //below was in original working condition, relocated for better updates
- // Generate brush silhouette
- //brushSilhouette = GenerateBrushSilhouette(p.Width, color);
- // Generate eraser silhouette
- //eraserSilhouette = GenerateEraserSilhouette(eraserSize);
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #24 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #9 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- //delete if unnecessary
- /*private Cursor CreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot)
- {
- IntPtr iconHandle = bitmap.GetHicon();
- Icon customIcon = Icon.FromHandle(iconHandle);
- Cursor customCursor = new Cursor(customIcon.Handle);
- DestroyIcon(iconHandle); // Cleanup icon handle to avoid resource leaks
- return customCursor;
- }
- [DllImport("user32.dll")]
- private static extern bool DestroyIcon(IntPtr handle);*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #33 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*IntPtr cursorHandle = bitmap.GetHicon();
- Cursor cursor = new Cursor(cursorHandle);
- cursor.HotSpot = new Point(xHotSpot, yHotSpot);
- return cursor;
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #33 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #30 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*IntPtr cursorHandle = bitmap.GetHicon();
- return new Cursor(cursorHandle);
- }*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #30 Silhouette adding persistent values
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*protected override void OnPaintBackground(PaintEventArgs e)
- {
- // Override the OnPaintBackground method to prevent default background painting.
- // This helps in avoiding the runtime exception when minimizing using Windows key + D.
- // Do nothing here to prevent the default behavior.
- }*/
- }
- }
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- Start #1 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- /*.o0o0o0o0o0o0o0o0o0o0o0o0o0o.
- End #1 Silhouette
- .o0o0o0o0o0o0o0o0o0o0o0o0o0o.*/
- ==++"Form1.Designer.cs" File 2/2 SourceCode::++==
- namespace Simple_Drawing_Application
- {
- partial class Form1
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
- this.label1 = new System.Windows.Forms.Label();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.menuStrip1 = new System.Windows.Forms.MenuStrip();
- this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.loadImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.quitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.selectColorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.setFontSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.selectBGToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.paintbrushToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.eraserToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.undoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.redoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.button1 = new System.Windows.Forms.Button();
- this.txt_color = new System.Windows.Forms.TextBox();
- this.button2 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.pb_canvas = new System.Windows.Forms.PictureBox();
- this.menuStrip1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pb_canvas)).BeginInit();
- this.SuspendLayout();
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.label1.Location = new System.Drawing.Point(1245, 39);
- this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(39, 18);
- this.label1.TabIndex = 1;
- this.label1.Text = "Size";
- this.label1.Visible = false;
- //
- // comboBox1
- //
- this.comboBox1.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Items.AddRange(new object[] {
- "8",
- "9",
- "10",
- "11",
- "12",
- "14",
- "16",
- "18",
- "20",
- "22",
- "24",
- "26",
- "28",
- "36",
- "48",
- "72"});
- this.comboBox1.Location = new System.Drawing.Point(1295, 38);
- this.comboBox1.Margin = new System.Windows.Forms.Padding(2);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(53, 23);
- this.comboBox1.TabIndex = 2;
- this.comboBox1.Visible = false;
- //
- // menuStrip1
- //
- this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
- this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.exitToolStripMenuItem,
- this.editToolStripMenuItem,
- this.paintbrushToolStripMenuItem,
- this.eraserToolStripMenuItem,
- this.undoToolStripMenuItem,
- this.redoToolStripMenuItem});
- this.menuStrip1.Location = new System.Drawing.Point(0, 0);
- this.menuStrip1.Name = "menuStrip1";
- this.menuStrip1.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1);
- this.menuStrip1.Size = new System.Drawing.Size(1352, 24);
- this.menuStrip1.TabIndex = 3;
- this.menuStrip1.Text = "menuStrip1";
- //
- // exitToolStripMenuItem
- //
- this.exitToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.loadImageToolStripMenuItem,
- this.saveImageToolStripMenuItem,
- this.quitToolStripMenuItem});
- this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
- this.exitToolStripMenuItem.Size = new System.Drawing.Size(43, 22);
- this.exitToolStripMenuItem.Text = "File";
- //
- // loadImageToolStripMenuItem
- //
- this.loadImageToolStripMenuItem.Name = "loadImageToolStripMenuItem";
- this.loadImageToolStripMenuItem.Size = new System.Drawing.Size(151, 22);
- this.loadImageToolStripMenuItem.Text = "Load Image";
- this.loadImageToolStripMenuItem.Click += new System.EventHandler(this.loadImageToolStripMenuItem_Click);
- //
- // saveImageToolStripMenuItem
- //
- this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem";
- this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(151, 22);
- this.saveImageToolStripMenuItem.Text = "Save Image";
- this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click);
- //
- // quitToolStripMenuItem
- //
- this.quitToolStripMenuItem.Name = "quitToolStripMenuItem";
- this.quitToolStripMenuItem.Size = new System.Drawing.Size(151, 22);
- this.quitToolStripMenuItem.Text = "Quit";
- this.quitToolStripMenuItem.Click += new System.EventHandler(this.quitToolStripMenuItem_Click);
- //
- // editToolStripMenuItem
- //
- this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.selectColorToolStripMenuItem,
- this.setFontSizeToolStripMenuItem,
- this.selectBGToolStripMenuItem,
- this.clearToolStripMenuItem});
- this.editToolStripMenuItem.Name = "editToolStripMenuItem";
- this.editToolStripMenuItem.Size = new System.Drawing.Size(44, 22);
- this.editToolStripMenuItem.Text = "Edit";
- //
- // selectColorToolStripMenuItem
- //
- this.selectColorToolStripMenuItem.Name = "selectColorToolStripMenuItem";
- this.selectColorToolStripMenuItem.Size = new System.Drawing.Size(163, 22);
- this.selectColorToolStripMenuItem.Text = "Select Color";
- this.selectColorToolStripMenuItem.Click += new System.EventHandler(this.selectColorToolStripMenuItem_Click);
- //
- // setFontSizeToolStripMenuItem
- //
- this.setFontSizeToolStripMenuItem.Name = "setFontSizeToolStripMenuItem";
- this.setFontSizeToolStripMenuItem.Size = new System.Drawing.Size(163, 22);
- this.setFontSizeToolStripMenuItem.Text = "Set Font Size";
- this.setFontSizeToolStripMenuItem.Click += new System.EventHandler(this.setFontSizeToolStripMenuItem_Click);
- //
- // selectBGToolStripMenuItem
- //
- this.selectBGToolStripMenuItem.Name = "selectBGToolStripMenuItem";
- this.selectBGToolStripMenuItem.Size = new System.Drawing.Size(163, 22);
- this.selectBGToolStripMenuItem.Text = "Select BG";
- this.selectBGToolStripMenuItem.Click += new System.EventHandler(this.selectBGToolStripMenuItem_Click);
- //
- // clearToolStripMenuItem
- //
- this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
- this.clearToolStripMenuItem.Size = new System.Drawing.Size(163, 22);
- this.clearToolStripMenuItem.Text = "Clear";
- this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
- //
- // paintbrushToolStripMenuItem
- //
- this.paintbrushToolStripMenuItem.Name = "paintbrushToolStripMenuItem";
- this.paintbrushToolStripMenuItem.Size = new System.Drawing.Size(90, 22);
- this.paintbrushToolStripMenuItem.Text = "Paintbrush";
- this.paintbrushToolStripMenuItem.Click += new System.EventHandler(this.paintbrushToolStripMenuItem_Click);
- //
- // eraserToolStripMenuItem
- //
- this.eraserToolStripMenuItem.Name = "eraserToolStripMenuItem";
- this.eraserToolStripMenuItem.Size = new System.Drawing.Size(61, 22);
- this.eraserToolStripMenuItem.Text = "Eraser";
- this.eraserToolStripMenuItem.Click += new System.EventHandler(this.eraserToolStripMenuItem_Click);
- //
- // undoToolStripMenuItem
- //
- this.undoToolStripMenuItem.Name = "undoToolStripMenuItem";
- this.undoToolStripMenuItem.Size = new System.Drawing.Size(52, 22);
- this.undoToolStripMenuItem.Text = "Undo";
- //
- // redoToolStripMenuItem
- //
- this.redoToolStripMenuItem.Name = "redoToolStripMenuItem";
- this.redoToolStripMenuItem.Size = new System.Drawing.Size(52, 22);
- this.redoToolStripMenuItem.Text = "Redo";
- //
- // button1
- //
- this.button1.Font = new System.Drawing.Font("Kdam Thmor Pro", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.button1.Location = new System.Drawing.Point(1286, 225);
- this.button1.Margin = new System.Windows.Forms.Padding(2);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(64, 85);
- this.button1.TabIndex = 4;
- this.button1.Text = "Color";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Visible = false;
- //
- // txt_color
- //
- this.txt_color.Font = new System.Drawing.Font("Kdam Thmor Pro", 8.999999F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.txt_color.Location = new System.Drawing.Point(1286, 314);
- this.txt_color.Margin = new System.Windows.Forms.Padding(2);
- this.txt_color.Name = "txt_color";
- this.txt_color.ReadOnly = true;
- this.txt_color.Size = new System.Drawing.Size(65, 26);
- this.txt_color.TabIndex = 5;
- this.txt_color.Visible = false;
- //
- // button2
- //
- this.button2.Font = new System.Drawing.Font("Kdam Thmor Pro", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.button2.Location = new System.Drawing.Point(1286, 119);
- this.button2.Margin = new System.Windows.Forms.Padding(2);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(62, 43);
- this.button2.TabIndex = 6;
- this.button2.Text = "Save";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Visible = false;
- //
- // button3
- //
- this.button3.Font = new System.Drawing.Font("Kdam Thmor Pro", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.button3.Location = new System.Drawing.Point(1286, 367);
- this.button3.Margin = new System.Windows.Forms.Padding(2);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(62, 43);
- this.button3.TabIndex = 7;
- this.button3.Text = "Clear";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Visible = false;
- //
- // pb_canvas
- //
- this.pb_canvas.BackColor = System.Drawing.Color.Transparent;
- this.pb_canvas.Cursor = System.Windows.Forms.Cursors.Default;
- this.pb_canvas.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pb_canvas.Location = new System.Drawing.Point(0, 24);
- this.pb_canvas.Margin = new System.Windows.Forms.Padding(2);
- this.pb_canvas.Name = "pb_canvas";
- this.pb_canvas.Size = new System.Drawing.Size(1352, 703);
- this.pb_canvas.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
- this.pb_canvas.TabIndex = 0;
- this.pb_canvas.TabStop = false;
- this.pb_canvas.WaitOnLoad = true;
- this.pb_canvas.Paint += new System.Windows.Forms.PaintEventHandler(this.pb_canvas_Paint);
- this.pb_canvas.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pb_canvas_MouseDown);
- this.pb_canvas.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pb_canvas_MouseMove);
- this.pb_canvas.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pb_canvas_MouseUp);
- //
- // Form1
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BackColor = System.Drawing.SystemColors.ButtonHighlight;
- this.ClientSize = new System.Drawing.Size(1352, 727);
- this.Controls.Add(this.button3);
- this.Controls.Add(this.button2);
- this.Controls.Add(this.txt_color);
- this.Controls.Add(this.button1);
- this.Controls.Add(this.comboBox1);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.pb_canvas);
- this.Controls.Add(this.menuStrip1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.MainMenuStrip = this.menuStrip1;
- this.Margin = new System.Windows.Forms.Padding(2);
- this.Name = "Form1";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Absence of Euphoria (Default Size = 12 14 23 Eraser = 50 26 Color = #FF0000 #FF80" +
- "40)";
- this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
- this.Load += new System.EventHandler(this.Form1_Load);
- this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
- this.Resize += new System.EventHandler(this.Form1_Resize);
- this.menuStrip1.ResumeLayout(false);
- this.menuStrip1.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pb_canvas)).EndInit();
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.PictureBox pb_canvas;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.ComboBox comboBox1;
- private System.Windows.Forms.MenuStrip menuStrip1;
- private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem quitToolStripMenuItem;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.TextBox txt_color;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.ToolStripMenuItem paintbrushToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem eraserToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem loadImageToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem selectColorToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem setFontSizeToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem selectBGToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem undoToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem redoToolStripMenuItem;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement