Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.24 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. using System.Threading;
  11.  
  12. namespace Client
  13. {
  14. public partial class Form1 : Form
  15. {
  16. // note !-> all the consts' values mean this.width (OR height) / value
  17. private const int ALLIGMENT_FROM_TOP = 20; // the alligment from the top of the screen
  18. private const int ALLIGMENT_FROM_LEFT = 20; // the alligment from the Left of the screen
  19. private const int LOG_IN_FORM_TXT_X_SIZE = 4; // the size of the text boxes in x axis which will be shown on the screen
  20. private const int LOG_IN_FORM_TEXT_SECTOR_HEIGHT = 2; // the height of the username password and email text boxes
  21. private const int LOG_IN_FORM_ALLGIMENT_FROM_TEXT_TO_LABEL = 50; // alligment from label to textbox
  22. private const int LOG_IN_FORM_PICBOX_HEIGHT = 4; // the height of the buttons (width / 4)
  23. private const int SIGN_OUT_FORM_BACK_HEIGHT_WIDTH = 6; // the height and width of the back button
  24. private const int CLOSE_GAME_BUTTON_WIDTH = 7; // the width of the close button
  25. private const int CLOSE_GAME_BUTTON_HEIGHT = 16; // the height of the close button
  26. private const int MAIN_FORM_PICBOX_HEIGHT = 10; // the height of the picture boxes in main form
  27. private const int MAIN_FORM_PICBOX_WIDTH = 5; // the width of the picture boxes in the main form
  28. private const int MAIN_FORM_LOG_OUT_HEIGHT = 12; // the height of the log out button
  29. private const int MAIN_FORM_LOG_OUT_WIDTH = 7; // the width of the log out button
  30. private const int BEST_SCORES_FORM_PB_HEIGHT = 4; // the height of the best scores pictures
  31. private const int BEST_SCORES_FORM_PB_WIDTH = 5; // the width of the best scores picture
  32.  
  33. //private static int yAxisSpace; // the space remains after the alligment is substracted in y axis
  34. //private static int xAxisSpace; // the space remains after the alligment is substracted in x axis
  35.  
  36. private MyPictureBox PBClose; // the close button, <> needs to be disposed
  37. private Thread t; // Thread to handle messages from the server
  38. private Stream stream; // creates a connection with the server by ip and port
  39. private int alligmentFromSubjectY; // the alligment in y axis from the subject
  40. private string uid; // the username of the signed in user
  41.  
  42. public Form1()
  43. {
  44. this.stream = new Stream("127.0.0.1", 8686);
  45.  
  46. t = new Thread(handleMessage);
  47. t.Start();
  48.  
  49. InitializeComponent();
  50.  
  51. this.Width = Screen.PrimaryScreen.Bounds.Width;
  52. this.Height = Screen.PrimaryScreen.Bounds.Height;
  53.  
  54. InitStaticVars();
  55. InitLoginScreen(null, EventArgs.Empty);
  56. //InitSignUp(null, EventArgs.Empty);
  57. //InitMainScreen(null, EventArgs.Empty);
  58. //InitBestScores(null, EventArgs.Empty);
  59. //KeyValuePair<string, string>[] arr = new KeyValuePair<string, string>[3];
  60. //arr[0] = new KeyValuePair<string, string>("tal", "100");
  61. //arr[1] = new KeyValuePair<string, string>("Dolev", "0");
  62. //arr[2] = new KeyValuePair<string, string>("yarin", "10");
  63. //changeBestScores(arr);
  64. //CleanAllControlers();
  65. }
  66.  
  67. /// <summary>
  68. /// initializes all static variables of custom classes, and current class
  69. /// </summary>
  70. public void InitStaticVars()
  71. {
  72. // MyTxtBox Class:
  73. // the default width of the text box
  74. MyTxtBox._width = (this.Width / LOG_IN_FORM_TXT_X_SIZE);
  75.  
  76. // current class:
  77. // sets the close button
  78. PBClose = new MyPictureBox("PBClose", "close", new Size(this.Width / CLOSE_GAME_BUTTON_WIDTH, this.Height / CLOSE_GAME_BUTTON_HEIGHT));
  79. PBClose.Location = new Point(this.Width / 2 - PBClose.Width / 2, this.Height - PBClose.Height - this.Height / ALLIGMENT_FROM_TOP);
  80. PBClose.Click += PBClose_Click;
  81. this.Controls.Add(PBClose);
  82.  
  83. // sets the alligment from top of screen
  84. alligmentFromSubjectY = this.Height / ALLIGMENT_FROM_TOP;
  85.  
  86. uid = "tal";
  87. }
  88.  
  89. /// <summary>
  90. /// makes the login is screen
  91. /// </summary>
  92. public void InitLoginScreen(object sender, EventArgs args)
  93. {
  94. int reminingY = this.Height;
  95. int nextYPos = 0;
  96. int xOfTextBoxes = 0;
  97. int sizeOfPictureBox = 0;
  98. int alligmentFromPictureBox = 0;
  99. int alligmentFromTextBoxes = 0;
  100. int alligmentFromTextBoxesToLabels = this.Width / LOG_IN_FORM_ALLGIMENT_FROM_TEXT_TO_LABEL;
  101. int xOfPicBoxes = 0;
  102. List<Control> cont = new List<Control>();
  103.  
  104. // sets the background of the page
  105. this.BackgroundImage = Client.Properties.Resources.loginBG;
  106.  
  107. // sets the color of the letters
  108. this.ForeColor = Color.White;
  109.  
  110. // sets the subject label
  111. Label LBLSubject = new MyLabel("Please Log In", "LBLSubject"); // i create a label to know the width of its text
  112. LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
  113. cont.Add(LBLSubject);
  114.  
  115. nextYPos = LBLSubject.Location.Y + alligmentFromSubjectY + LBLSubject.Height; // begining of details section
  116. reminingY -= nextYPos; // sets the space of details section
  117.  
  118. // sets the text box of username
  119. TextBox TXTuserName = new MyTxtBox("TXTusername"); // i create a label to know the height of its font
  120. alligmentFromTextBoxes = ((reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT) - (TXTuserName.Height * 2)) / 3; // generates the needed alligment
  121. nextYPos += alligmentFromTextBoxes;
  122. reminingY -= reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT; // sets the space of buttons section
  123.  
  124. TXTuserName.Location = new Point((this.Width / 2) - (TXTuserName.Width / 2), nextYPos);
  125. cont.Add(TXTuserName);
  126.  
  127. // sets the label of username
  128. Label LBLusername = new MyLabel("UserName: ", "LBLusername"); // sets the label of the userName
  129. LBLusername.Location = new Point(TXTuserName.Location.X - LBLusername.Width - alligmentFromTextBoxesToLabels, nextYPos);
  130. cont.Add(LBLusername);
  131.  
  132. nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the position of the next textBox
  133. xOfTextBoxes = TXTuserName.Location.X;
  134.  
  135. // sets the text box of password
  136. TextBox TXTpsw = new MyTxtBox(new Point(xOfTextBoxes, nextYPos), "TXTpsw");
  137. cont.Add(TXTpsw);
  138.  
  139. // sets the label of password
  140. Label LBLpsw = new MyLabel("password: ", "LBLpsw"); // sets the password label
  141. LBLpsw.Location = new Point(xOfTextBoxes - LBLpsw.Width - alligmentFromTextBoxesToLabels, nextYPos);
  142. cont.Add(LBLpsw);
  143.  
  144. nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the begining of the buttons sector
  145.  
  146. // sets the buttons section
  147. sizeOfPictureBox = reminingY / LOG_IN_FORM_PICBOX_HEIGHT;
  148. reminingY -= (sizeOfPictureBox * 2);
  149. alligmentFromPictureBox = reminingY / 2;
  150.  
  151. // sets the sign in button
  152. PictureBox PBSignIn = new MyPictureBox("PBSignIn", "SignIn", new Size(TXTuserName.Width, sizeOfPictureBox));
  153. xOfPicBoxes = (this.Width / 2) - (PBSignIn.Width / 2); // sets the x of picture boxes
  154. PBSignIn.Location = new Point(xOfPicBoxes, nextYPos);
  155. PBSignIn.Click += (EventHandler)PBSign_In_Click;
  156. cont.Add(PBSignIn);
  157.  
  158. nextYPos += alligmentFromPictureBox;
  159.  
  160. // sets the signup button
  161. PictureBox PBSignUp = new MyPictureBox("PBSignUp", "SignUp", new Size(PBSignIn.Width, sizeOfPictureBox));
  162. PBSignUp.Location = new Point(xOfPicBoxes, nextYPos);
  163. PBSignUp.Click += (EventHandler)(CleanAllControlers);
  164. PBSignUp.Click += (EventHandler)InitSignUp;
  165. cont.Add(PBSignUp);
  166.  
  167. this.Controls.AddRange(cont.ToArray());
  168. }
  169.  
  170. /// <summary>
  171. /// sets the form to be sign up page
  172. /// </summary>
  173. public void InitSignUp(object sender, EventArgs args)
  174. {
  175. int reminingY = this.Height;
  176. int nextYPos = 0;
  177. int xOfTextBoxes = 0;
  178. int sizeOfPictureBox = 0;
  179. int alligmentFromPictureBox = 0;
  180. int alligmentFromTextBoxes = 0;
  181. int alligmentFromTextBoxesToLabels = this.Width / LOG_IN_FORM_ALLGIMENT_FROM_TEXT_TO_LABEL;
  182. int xOfPicBoxes = 0;
  183. List<Control> cont = new List<Control>();
  184.  
  185. // sets the background
  186. this.BackgroundImage = Properties.Resources.signUpBG;
  187.  
  188. // sets the color of the letters
  189. this.ForeColor = Color.Black;
  190.  
  191. // sets the subject label
  192. Label LBLSubject = new MyLabel("Please Sign Up", "LBLSubject"); // i create a label to know the width of its text
  193. LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
  194. cont.Add(LBLSubject);
  195.  
  196. nextYPos = LBLSubject.Location.Y + alligmentFromSubjectY + LBLSubject.Height; // begining of details section
  197. reminingY -= nextYPos; // sets the space of details section
  198.  
  199. // sets the text box of username
  200. TextBox TXTuserName = new MyTxtBox("TXTusername"); // i create a label to know the height of its font
  201. alligmentFromTextBoxes = ((reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT) - (TXTuserName.Height * 3)) / 4; // generates the needed alligment
  202. nextYPos += alligmentFromTextBoxes;
  203. reminingY -= reminingY / LOG_IN_FORM_TEXT_SECTOR_HEIGHT; // sets the space of buttons section
  204.  
  205. TXTuserName.Location = new Point((this.Width / 2) - (TXTuserName.Width / 2), nextYPos);
  206. cont.Add(TXTuserName);
  207.  
  208. // sets the label of username
  209. Label LBLusername = new MyLabel("UserName: ", "LBLusername"); // sets the label of the userName
  210. LBLusername.Location = new Point(TXTuserName.Location.X - LBLusername.Width - alligmentFromTextBoxesToLabels, nextYPos);
  211. cont.Add(LBLusername);
  212.  
  213. nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the position of the next textBox
  214. xOfTextBoxes = TXTuserName.Location.X;
  215.  
  216. // sets the text box of password
  217. TextBox TXTpsw = new MyTxtBox(new Point(xOfTextBoxes, nextYPos), "TXTpsw");
  218. cont.Add(TXTpsw);
  219.  
  220. // sets the label of password
  221. Label LBLpsw = new MyLabel("password: ", "LBLpsw"); // sets the password label
  222. LBLpsw.Location = new Point(xOfTextBoxes - LBLpsw.Width - alligmentFromTextBoxesToLabels, nextYPos);
  223. cont.Add(LBLpsw);
  224.  
  225. nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the position of the next textBox
  226.  
  227. // sets the text box of email
  228. TextBox TXTemail = new MyTxtBox(new Point(xOfTextBoxes, nextYPos), "TXTemail");
  229. cont.Add(TXTemail);
  230.  
  231. // sets the label of email
  232. Label LBLemail = new MyLabel("email: ", "LBLemail");
  233. LBLemail.Location = new Point(xOfTextBoxes - LBLemail.Width - alligmentFromTextBoxesToLabels, nextYPos);
  234. cont.Add(LBLemail);
  235.  
  236. nextYPos += (TXTuserName.Height + alligmentFromTextBoxes); // sets the begining of the buttons sector
  237.  
  238. // sets the buttons section
  239. sizeOfPictureBox = reminingY / LOG_IN_FORM_PICBOX_HEIGHT;
  240. reminingY -= (sizeOfPictureBox * 2);
  241. alligmentFromPictureBox = reminingY / 2;
  242.  
  243. // sets the sign up button
  244. PictureBox PBSignUp = new MyPictureBox("PBSignUp", "SignUp", new Size(TXTemail.Width, sizeOfPictureBox));
  245. xOfPicBoxes = (this.Width / 2) - (PBSignUp.Width / 2); // sets the x of picture boxes
  246. PBSignUp.Location = new Point(xOfPicBoxes, nextYPos);
  247. PBSignUp.Click += (EventHandler)PBSign_Up_Click;
  248. //PBSignUp.Click += (EventHandler)CleanAllControlers;
  249. cont.Add(PBSignUp);
  250.  
  251. // sets the back button
  252. int PCHeight = this.Height / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
  253. int PCWidth = this.Width / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
  254. PictureBox PBBack = new MyPictureBox("PBBack", "back", new Size(PCWidth, PCHeight));
  255. PBBack.Location = new Point(this.Width - PCWidth, this.Height / ALLIGMENT_FROM_TOP);
  256. PBBack.Click += (EventHandler)CleanAllControlers;
  257. PBBack.Click += (EventHandler)InitLoginScreen;
  258. cont.Add(PBBack);
  259.  
  260. this.Controls.AddRange(cont.ToArray());
  261. }
  262.  
  263. /// <summary>
  264. /// builds the main screen
  265. /// </summary>
  266. /// <param name="sender"></param>
  267. /// <param name="args"></param>
  268. public void InitMainScreen(object sender, EventArgs args)
  269. {
  270. int nextYPos = 0;
  271. int reminingY = PBClose.Location.Y;
  272. int heightOfPB = this.Height / MAIN_FORM_PICBOX_HEIGHT;
  273. int widthOfPB = this.Width / MAIN_FORM_PICBOX_WIDTH;
  274. int alligmentFromButtonsY = 0;
  275. int alligmentFromButtonsX = 0;
  276.  
  277. // sets the background of the screen
  278. this.BackgroundImage = Properties.Resources.mainScreenBG;
  279.  
  280. // sets the font color to black
  281. this.ForeColor = Color.Black;
  282.  
  283. // sets the subject label
  284. Label LBLSubject = new MyLabel("Hello " + uid, "LBLSubject"); // i create a label to know the width of its text
  285. LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
  286. this.Controls.Add(LBLSubject);
  287.  
  288. // configures all the propeties needed for the button
  289. nextYPos = LBLSubject.Location.Y + alligmentFromSubjectY;
  290. reminingY -= (nextYPos - heightOfPB * 2);
  291. alligmentFromButtonsY = reminingY / 3;
  292. nextYPos += (alligmentFromButtonsY / 2);
  293. alligmentFromButtonsX = (this.Width - widthOfPB * 3) / 3;
  294.  
  295. // sets the Join room button
  296. Button BTNJoin = new MyButton("BTNJoin", new Size(widthOfPB, heightOfPB), "Join Room");
  297. BTNJoin.Location = new Point(alligmentFromButtonsX, nextYPos);
  298. this.Controls.Add(BTNJoin);
  299.  
  300. // sets the Create room button
  301. Button BTNCreate = new MyButton("BTNCreate", new Size(widthOfPB, heightOfPB), "Create Room");
  302. BTNCreate.Location = new Point(this.Width - widthOfPB - alligmentFromButtonsX, nextYPos);
  303. this.Controls.Add(BTNCreate);
  304.  
  305. nextYPos += alligmentFromButtonsY;
  306.  
  307. // sets the best scores button
  308. Button BTNBest = new MyButton("BTNBest", new Size(widthOfPB, heightOfPB), "Best Scores");
  309. BTNBest.Location = new Point(alligmentFromButtonsX, nextYPos);
  310. BTNBest.Click += (EventHandler)CleanAllControlers;
  311. BTNBest.Click += (EventHandler)InitBestScores;
  312. BTNBest.Click += (EventHandler)BTNBest_Click;
  313. this.Controls.Add(BTNBest);
  314.  
  315. // sets the personal status
  316. Button BTNPersonal = new MyButton("BTNPersonal", new Size(widthOfPB, heightOfPB), "My Status");
  317. BTNPersonal.Location = new Point(this.Width - widthOfPB - alligmentFromButtonsX, nextYPos);
  318. this.Controls.Add(BTNPersonal);
  319.  
  320. // sets the logout button
  321. PictureBox PBLogOut = new MyPictureBox("PBLogOut", "signOut", new Size(this.Height / MAIN_FORM_LOG_OUT_WIDTH, this.Width / MAIN_FORM_LOG_OUT_HEIGHT));
  322. PBLogOut.Location = new Point(this.Width / ALLIGMENT_FROM_LEFT, this.Height / ALLIGMENT_FROM_TOP);
  323. PBLogOut.Click += (EventHandler)CleanAllControlers;
  324. PBLogOut.Click += (EventHandler)InitLoginScreen;
  325. PBLogOut.Click += (EventHandler)PBLogOut_Click;
  326. this.Controls.Add(PBLogOut);
  327. }
  328.  
  329. /// <summary>
  330. /// changes the form to show the best scores
  331. /// </summary>
  332. /// <param name="sender"></param>
  333. /// <param name="args"></param>
  334. private void InitBestScores(object sender, EventArgs args)
  335. {
  336. int reminingY = PBClose.Location.Y;
  337. int nextYPos = 0;
  338. int pictureBoxHeight = 0;
  339. int pictureBoxWidth = 0;
  340. int alligmentFromPicturesY = 0;
  341. int alligmentFromPictureX = 0;
  342.  
  343. // sets the background image to best scores BG
  344. this.BackgroundImage = Properties.Resources.winners;
  345.  
  346. // sets the font of the form to black
  347. this.ForeColor = Color.Black;
  348.  
  349. // sets the subject label
  350. Label LBLSubject = new MyLabel("Best Scores: ", "LBLSubject"); // i create a label to know the width of its text
  351. LBLSubject.Location = new Point((this.Width / 2) - (LBLSubject.Width / 2), alligmentFromSubjectY);
  352. this.Controls.Add(LBLSubject);
  353.  
  354. // creates the label that contains the first player's scores
  355. Label LBL1st = new MyLabel("ABCD", "LBL1st"); // i put text in the label so i can know its properties
  356.  
  357. // sets the next position for the picture boxes sector
  358. nextYPos += (LBLSubject.Location.Y + LBLSubject.Height + alligmentFromSubjectY);
  359. reminingY -= nextYPos;
  360.  
  361. // configures the properties of the picture boxes
  362. pictureBoxHeight = reminingY / BEST_SCORES_FORM_PB_HEIGHT;
  363. pictureBoxWidth = this.Width / BEST_SCORES_FORM_PB_WIDTH;
  364.  
  365. // configures the picture box sector
  366. alligmentFromPicturesY = (reminingY - pictureBoxHeight * 2 - LBL1st.Height * 2) / 2;
  367. alligmentFromPictureX = (this.Width - pictureBoxWidth * 3) / 4;
  368. nextYPos += alligmentFromPicturesY;
  369.  
  370. // sets the first place picture box
  371. PictureBox PB1st = new MyPictureBox("PB1st", "_1st", new Size(pictureBoxWidth, pictureBoxHeight));
  372. PB1st.Location = new Point(alligmentFromPictureX * 2 + pictureBoxWidth, nextYPos);
  373. this.Controls.Add(PB1st);
  374.  
  375. LBL1st.Location = new Point(PB1st.Location.X + PB1st.Width / 2, nextYPos - LBL1st.Height);
  376. this.Controls.Add(LBL1st);
  377.  
  378. // sets the postion to the next picture box
  379. nextYPos += alligmentFromPicturesY;
  380.  
  381. // sets the second best score picture box
  382. PictureBox PB2nd = new MyPictureBox("PB2nd", "_2nd", new Size(pictureBoxWidth, pictureBoxHeight));
  383. PB2nd.Location = new Point(alligmentFromPictureX, nextYPos);
  384. this.Controls.Add(PB2nd);
  385.  
  386. // sets the label of the second best score
  387. Label LBL2nd = new MyLabel("ABCD", "LBL2nd"); // i put text in the label so i can know its properties
  388. LBL2nd.Location = new Point(PB2nd.Location.X + PB2nd.Width / 2, PB2nd.Location.Y - LBL2nd.Height);
  389. this.Controls.Add(LBL2nd);
  390.  
  391. // sets the picture box of the second best score
  392. PictureBox PB3rd = new MyPictureBox("PB3rd", "_3rd", new Size(pictureBoxWidth, pictureBoxHeight));
  393. PB3rd.Location = new Point(this.Width - alligmentFromPictureX - PB3rd.Width, nextYPos);
  394. this.Controls.Add(PB3rd);
  395.  
  396. // sets the label of th ethird best score
  397. Label LBL3rd = new MyLabel("ABCD", "LBL3rd"); // i put text in the label so i can know its properties
  398. LBL3rd.Location = new Point(PB3rd.Location.X + PB3rd.Width / 2, nextYPos - LBL3rd.Height);
  399. this.Controls.Add(LBL3rd);
  400.  
  401. // sets the back button
  402. int PCHeight = this.Height / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
  403. int PCWidth = this.Width / SIGN_OUT_FORM_BACK_HEIGHT_WIDTH;
  404. PictureBox PBBack = new MyPictureBox("PBBack", "back", new Size(PCWidth, PCHeight));
  405. PBBack.Location = new Point(this.Width - PCWidth, this.Height / ALLIGMENT_FROM_TOP);
  406. PBBack.Click += (EventHandler)CleanAllControlers;
  407. PBBack.Click += (EventHandler)InitMainScreen;
  408. this.Controls.Add(PBBack);
  409. }
  410.  
  411. /// <summary>
  412. /// changes the best scores labels
  413. /// should be used when clicked on get best scores button, after InitBestScores was called
  414. /// </summary>
  415. /// <param name="arr">an array of pairs in which the key is the name of the user and the value is his score</param>
  416. private void changeBestScores(KeyValuePair<string, string>[] arr)
  417. {
  418. Label[] labels = new Label[3];
  419.  
  420. labels[0] = this.Controls.Find("LBL1st", false).FirstOrDefault() as Label;
  421. labels[1] = this.Controls.Find("LBL2nd", false).FirstOrDefault() as Label;
  422. labels[2] = this.Controls.Find("LBL3rd", false).FirstOrDefault() as Label;
  423.  
  424. for (int i = 0; i < 3; i++ )
  425. {
  426. if(labels[i] != null)
  427. {
  428. labels[i].Text = arr[i].Key + ": " + arr[i].Value;
  429. labels[i].Width = TextRenderer.MeasureText(labels[i].Text, labels[i].Font).Width;
  430. labels[i].Location = new Point(labels[i].Location.X - labels[i].Width / 2, labels[i].Location.Y);
  431. }
  432. }
  433. }
  434.  
  435. /// <summary>
  436. /// cleans the screen from all the controls on it
  437. /// </summary>
  438. private void CleanAllControlers(object sender, EventArgs args)
  439. {
  440. //foreach (Control c in this.Controls)
  441. //{
  442. // MessageBox.Show(c.GetType().ToString());
  443. // this.Controls.Remove(c);
  444. //}
  445.  
  446. this.Controls.Clear();
  447. this.Controls.Add(PBClose);
  448. }
  449.  
  450. private void PBClose_Click(object sender, EventArgs args)
  451. {
  452. this.Close();
  453. }
  454.  
  455. private void BTNBest_Click(object sender, EventArgs args)
  456. {
  457. // ... executed when best scores button clicked
  458. }
  459.  
  460. private void PBLogOut_Click(object sender, EventArgs args)
  461. {
  462. // ... executed when log out button is clicked
  463. }
  464.  
  465. /// <summary>
  466. /// sends the username, password and email to server according to the format for sign up
  467. /// </summary>
  468. private void PBSign_Up_Click(object sender, EventArgs args)
  469. {
  470. TextBox txtUserName = (TextBox)this.Controls.Find("TXTusername", false)[0];
  471. TextBox txtPassword = (TextBox)this.Controls.Find("TXTpsw", false)[0];
  472. TextBox txtEmail = (TextBox)this.Controls.Find("TXTemail", false)[0];
  473.  
  474. if (txtUserName != null && txtPassword != null && txtEmail != null)
  475. {
  476. this.stream.sendData(String.Format("203{0:00}{1}{2:00}{3}{4:00}{5}", txtUserName.Text.Length, txtUserName.Text, txtPassword.Text.Length, txtPassword.Text, txtEmail.Text.Length, txtEmail.Text));
  477. }
  478. }
  479.  
  480. /// <summary>
  481. /// sends the username and password to server according to the format for sign in
  482. /// </summary>
  483. private void PBSign_In_Click(object sender, EventArgs e)
  484. {
  485. TextBox txtUserName = (TextBox)this.Controls.Find("TXTusername", false)[0];
  486. TextBox txtPassword = (TextBox)this.Controls.Find("TXTpsw", false)[0];
  487.  
  488. if (txtUserName != null && txtPassword != null)
  489. {
  490. this.stream.sendData(String.Format("200{0:00}{1}{2:00}{3}", txtUserName.Text.Length, txtUserName.Text, txtPassword.Text.Length, txtPassword.Text));
  491. }
  492. }
  493.  
  494. private void handleMessage()
  495. {
  496. string msg = "";
  497. while (true)
  498. {
  499. msg = this.stream.recvData();
  500.  
  501. switch (int.Parse(msg))
  502. {
  503. case 1020:
  504. MessageBox.Show("Success Sign in");
  505. uid = ((TextBox)this.Controls.Find("TXTusername", false)[0]).Text;
  506. Invoke((MethodInvoker) (() => CleanAllControlers(null, EventArgs.Empty)));
  507. Invoke((MethodInvoker) (() => InitMainScreen(null, EventArgs.Empty)));
  508. break;
  509. case 1021:
  510. MessageBox.Show("Wrong Details Sign in");
  511. break;
  512. case 1022:
  513. MessageBox.Show("User is already connected Sign in");
  514. break;
  515. case 1040:
  516. MessageBox.Show("Success Sign up");
  517. Invoke((MethodInvoker) (() => CleanAllControlers(null, EventArgs.Empty)));
  518. Invoke((MethodInvoker) (() => this.InitLoginScreen(null, EventArgs.Empty)));
  519. break;
  520. case 1041:
  521. MessageBox.Show("WPass illegal Sign up");
  522. break;
  523. case 1042:
  524. MessageBox.Show("Username is already exists Sign up");
  525. break;
  526. case 1043:
  527. MessageBox.Show("Username is illegal Sign up");
  528. break;
  529. case 1044:
  530. MessageBox.Show("Other Sign up");
  531. break;
  532. }
  533. }
  534. }
  535.  
  536. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  537. {
  538. this.t.Abort();
  539. this.stream.sendData("299");
  540. this.stream.CloseStream();
  541. this.PBClose.Dispose();
  542. }
  543. }
  544. }
  545.  
  546.  
  547. // TODO:
  548. // set font according to resulution
  549. // remove the size of the Close button from the login and signup pages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement