Form1.cs 4.4 KB

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