Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Drawing;
- namespace Experiment1
- {
- class Experiment
- {
- static int schermHeight;
- static int schermWidth;
- static ExpForm scherm;
- static Button knop1;
- static Button knop2;
- public static void Main()
- {
- scherm = new ExpForm();
- knop1 = Createknop();
- knop2 = Createknop();
- knop2.Hide();
- scherm.Controls.Add(knop1);
- knop1.Click += Knop1Clicked;
- knop2.Click += Knop2Clicked;
- schermHeight = Screen.FromControl(scherm).Bounds.Height;
- schermWidth = Screen.FromControl(scherm).Bounds.Width;
- Application.Run(scherm);
- }
- private static void Knop1Clicked(object sender, System.EventArgs e)
- {
- Button clickedButton = sender as Button;
- clickedButton.Hide();
- Randomizeknop2();
- knop2.Show();
- scherm.Controls.Add(knop2);
- }
- public static Button Createknop()
- {
- Button knop = new Button();
- knop.Size = new Size(200, 100);
- knop.Location = new Point(650, 350);
- knop.Text = "Klik!";
- return knop;
- }
- public static void Randomizeknop2()
- {
- Random rnd = new Random();
- int size = rnd.Next(50, 350);
- int x = rnd.Next(0, schermWidth-size);
- int y = rnd.Next(0, schermHeight-size-65);
- knop2.Size = new Size(size, size);
- knop2.Location = new Point(x, y);
- knop2.Text = "Klik!";
- }
- private static void Knop2Clicked(object sender, System.EventArgs e)
- {
- Button clickedButton = sender as Button;
- clickedButton.Hide();
- knop1.Show();
- }
- }
- class ExpForm : Form
- {
- public ExpForm()
- {
- this.BackColor = Color.CadetBlue;
- this.Text = "Experiment";
- this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement