Form1.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. // This is the code for your desktop app.
  11. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
  12. namespace SketchAssistant
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. //Dialog to select a file.
  21. OpenFileDialog openFileDialogLeft = new OpenFileDialog();
  22. //Image loaded on the left
  23. Image leftImage = null;
  24. //Image on the right
  25. Image rightImage = null;
  26. private void Form1_Load(object sender, EventArgs e)
  27. {
  28. this.DoubleBuffered = true;
  29. //Connect the Paint event of the left picture box to the event handler method.
  30. pictureBoxLeft.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxLeft_Paint);
  31. pictureBoxRight.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxRight_Paint);
  32. }
  33. //Resize Function connected to the form resize event, will refresh the form when it is resized
  34. private void Form1_Resize(object sender, System.EventArgs e)
  35. {
  36. this.Refresh();
  37. }
  38. private void pictureBoxLeft_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  39. {
  40. //Draw the left image
  41. if(leftImage != null)
  42. {
  43. pictureBoxLeft.Image = leftImage;
  44. }
  45. }
  46. private void pictureBoxRight_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  47. {
  48. //Draw the right image
  49. if (rightImage != null)
  50. {
  51. pictureBoxRight.Image = rightImage;
  52. }
  53. }
  54. // A Table Layout with one row and two columns.
  55. // Columns are 50% so that the window is evenly split.
  56. // The size is manually set relative to the window size.
  57. // TODO: Maybe change this to automatically be the size of a parent container...
  58. private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
  59. {
  60. }
  61. private void fileToolStripMenuItem_Click(object sender, EventArgs e)
  62. {
  63. }
  64. //Load button, will open an OpenFileDialog
  65. private void loadToolStripMenuItem_Click(object sender, EventArgs e)
  66. {
  67. openFileDialogLeft.Filter = "Image|*.jpg;*.png;*.jpeg";
  68. if(openFileDialogLeft.ShowDialog() == DialogResult.OK)
  69. {
  70. toolStripLoadStatus.Text = openFileDialogLeft.SafeFileName;
  71. leftImage = Image.FromFile(openFileDialogLeft.FileName);
  72. //Refresh the left image box when the content is changed
  73. this.Refresh();
  74. pictureBoxLeft.Refresh();
  75. }
  76. }
  77. private void toolStripStatusLabel1_Click(object sender, EventArgs e)
  78. {
  79. }
  80. private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  81. {
  82. }
  83. private void pictureBoxLeft_Click(object sender, EventArgs e)
  84. {
  85. }
  86. //Button to create a new Canvas. Will create an empty image
  87. //which is the size of the left image, if there is one.
  88. //If there is no image loaded the canvas will be the size of the right picture box
  89. private void toolStripButton1_Click(object sender, EventArgs e)
  90. {
  91. if (leftImage == null)
  92. {
  93. rightImage = new Bitmap(pictureBoxRight.Width, pictureBoxRight.Height);
  94. using (Graphics grp = Graphics.FromImage(rightImage))
  95. {
  96. grp.FillRectangle(Brushes.White, 0, 0, pictureBoxRight.Width + 10, pictureBoxRight.Height + 10);
  97. }
  98. }
  99. else
  100. {
  101. rightImage = new Bitmap(leftImage.Width, leftImage.Height);
  102. using (Graphics grp = Graphics.FromImage(rightImage))
  103. {
  104. grp.FillRectangle(Brushes.White, 0, 0, leftImage.Width + 10, leftImage.Height + 10);
  105. }
  106. }
  107. this.Refresh();
  108. pictureBoxRight.Refresh();
  109. }
  110. }
  111. }