Guest User

Form1.cs

a guest
Jul 14th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  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.  
  11. namespace imgMessCons
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. String pathTxtWrite = string.Empty,
  21. pathImgWrite = string.Empty,
  22. pathTxtRead = string.Empty,
  23. pathImgRead = string.Empty;
  24.  
  25. ImgProc bmpWrite,
  26. bmpRead;
  27.  
  28. int step;
  29.  
  30. private void Form1_Load(object sender, EventArgs e)
  31. {
  32. labelSeparation1.AutoSize = false;
  33. labelSeparation1.Height = 4;
  34. labelSeparation1.BorderStyle = BorderStyle.Fixed3D;
  35.  
  36. labelSepatation2.AutoSize = false;
  37. labelSepatation2.Height = 4;
  38. labelSepatation2.BorderStyle = BorderStyle.Fixed3D;
  39.  
  40. numericUpDownWriteStep.Minimum = 1;
  41. numericUpDownWriteStep.Maximum = 255;
  42.  
  43. labelWriteTxtPathState.Text = "Empty";
  44. labelWriteImgPathState.Text = "Empty";
  45. labelWriteState.Text = "Lock";
  46. labelWriteBusyReady.Text = "Ready";
  47. buttonWriteMess.Enabled = false;
  48.  
  49. labelReadTxtPathState.Text = "Empty";
  50. labelReadImgPathState.Text = "Empty";
  51. labelReadState.Text = "Lock";
  52. labelReadBuseReady.Text = "Ready";
  53. buttonReadMess.Enabled = false;
  54. }
  55.  
  56. private void buttonTextPath_Click(object sender, EventArgs e)
  57. {
  58. OpenFileDialog ofd = new OpenFileDialog();
  59. ofd.Filter = "Message original (TXT)|*.txt";
  60. if(ofd.ShowDialog() == DialogResult.OK)
  61. {
  62. pathTxtWrite = ofd.FileName;
  63. textBoxWriteTxtPath.Text = pathTxtWrite;
  64. }
  65.  
  66. CheckWriteMessageState();
  67. }
  68.  
  69. private void CheckWriteMessageState()
  70. {
  71. labelWriteState.Text = "Lock";
  72. buttonWriteMess.Enabled = false;
  73. if((textBoxWriteTxtPath.Text.Length > 0) && (textBoxWriteImgPath.Text.Length > 0))
  74. {
  75. labelWriteState.Text = "Unlock";
  76. buttonWriteMess.Enabled = true;
  77. }
  78. }
  79.  
  80. private void buttonClose_Click(object sender, EventArgs e)
  81. {
  82. this.Close();
  83. }
  84.  
  85. private void buttonWriteImgPath_Click(object sender, EventArgs e)
  86. {
  87. OpenFileDialog ofd = new OpenFileDialog();
  88. ofd.Filter = "Image for message (PNG)|*png";
  89.  
  90. if(ofd.ShowDialog() == DialogResult.OK)
  91. {
  92. pathImgWrite = ofd.FileName;
  93. textBoxWriteImgPath.Text = pathImgWrite;
  94. }
  95. CheckWriteMessageState();
  96. }
  97.  
  98. private void buttonReadTxtPath_Click(object sender, EventArgs e)
  99. {
  100. OpenFileDialog ofd = new OpenFileDialog();
  101. ofd.Filter = "Message from image (TXT)|*txt";
  102. if(ofd.ShowDialog() == DialogResult.OK)
  103. {
  104. pathTxtRead = ofd.FileName;
  105. textBoxReadTxtPath.Text = pathTxtRead;
  106. }
  107.  
  108. CheckReadMessageState();
  109. }
  110.  
  111. private void CheckReadMessageState()
  112. {
  113. labelReadState.Text = "Lock";
  114. buttonReadMess.Enabled = false;
  115.  
  116. if((textBoxReadTxtPath.Text.Length > 0) && (textBoxReadImgPath.Text.Length > 0))
  117. {
  118. labelReadState.Text = "Unlock";
  119. buttonReadMess.Enabled = true;
  120. }
  121. }
  122.  
  123. private void buttonReadImgPath_Click(object sender, EventArgs e)
  124. {
  125. OpenFileDialog ofd = new OpenFileDialog();
  126. ofd.Filter = "Image with message (PNG)|*png";
  127. if(ofd.ShowDialog() == DialogResult.OK)
  128. {
  129. pathImgRead = ofd.FileName;
  130. textBoxReadImgPath.Text = pathImgRead;
  131. }
  132.  
  133. CheckReadMessageState();
  134.  
  135. }
  136.  
  137. private void buttonWriteMess_Click(object sender, EventArgs e)
  138. {
  139. labelWriteBusyReady.Text = "Busy";
  140.  
  141. step = (int)numericUpDownWriteStep.Value;
  142. bmpWrite = new ImgProc(pathImgWrite);
  143. bmpWrite.WriteMessage(pathTxtWrite, step);
  144. bmpWrite.SaveImg(pathImgWrite);
  145.  
  146. bmpWrite = null;
  147.  
  148. pathTxtWrite = string.Empty;
  149. pathImgWrite = string.Empty;
  150.  
  151. textBoxWriteTxtPath.Text = string.Empty;
  152. textBoxWriteImgPath.Text = string.Empty;
  153.  
  154. CheckWriteMessageState();
  155.  
  156. labelWriteBusyReady.Text = "Ready";
  157.  
  158.  
  159. }
  160.  
  161. private void buttonReadMess_Click(object sender, EventArgs e)
  162. {
  163. labelReadBuseReady.Text = "Busy";
  164.  
  165. bmpRead = new ImgProc(pathImgRead);
  166.  
  167. bmpRead.ReadMessage(pathTxtRead);
  168.  
  169. bmpRead = null;
  170.  
  171. pathTxtRead = string.Empty;
  172. pathImgRead = string.Empty;
  173.  
  174. textBoxReadTxtPath.Text = string.Empty;
  175. textBoxReadImgPath.Text = string.Empty;
  176.  
  177. CheckReadMessageState();
  178.  
  179. labelReadBuseReady.Text = "Ready";
  180.  
  181. }
  182.  
  183.  
  184. }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment