Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7.  
  8. namespace Experiment1
  9. {
  10. class Experiment
  11. {
  12. static int schermHeight;
  13. static int schermWidth;
  14. static ExpForm scherm;
  15. static Button knop1;
  16. static Button knop2;
  17.  
  18. public static void Main()
  19. {
  20. scherm = new ExpForm();
  21. knop1 = Createknop();
  22. knop2 = Createknop();
  23. knop2.Hide();
  24. scherm.Controls.Add(knop1);
  25. knop1.Click += Knop1Clicked;
  26. knop2.Click += Knop2Clicked;
  27. schermHeight = Screen.FromControl(scherm).Bounds.Height;
  28. schermWidth = Screen.FromControl(scherm).Bounds.Width;
  29. Application.Run(scherm);
  30. }
  31. private static void Knop1Clicked(object sender, System.EventArgs e)
  32. {
  33. Button clickedButton = sender as Button;
  34. clickedButton.Hide();
  35. Randomizeknop2();
  36. knop2.Show();
  37. scherm.Controls.Add(knop2);
  38. }
  39.  
  40. public static Button Createknop()
  41. {
  42. Button knop = new Button();
  43. knop.Size = new Size(200, 100);
  44. knop.Location = new Point(650, 350);
  45. knop.Text = "Klik!";
  46. return knop;
  47. }
  48. public static void Randomizeknop2()
  49. {
  50. Random rnd = new Random();
  51. int size = rnd.Next(50, 350);
  52. int x = rnd.Next(0, schermWidth-size);
  53. int y = rnd.Next(0, schermHeight-size-65);
  54. knop2.Size = new Size(size, size);
  55. knop2.Location = new Point(x, y);
  56. knop2.Text = "Klik!";
  57. }
  58. private static void Knop2Clicked(object sender, System.EventArgs e)
  59. {
  60. Button clickedButton = sender as Button;
  61. clickedButton.Hide();
  62. knop1.Show();
  63. }
  64. }
  65. class ExpForm : Form
  66. {
  67. public ExpForm()
  68. {
  69. this.BackColor = Color.CadetBlue;
  70. this.Text = "Experiment";
  71. this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement