private void button1_Click(object sender, EventArgs e) { button1.Size = new Size(RandomGenerator.NextInt(20, 125), RandomGenerator.NextInt(20, 125)); button1.Location = new Point( NormalDistributor.WeightedRandom(0, this.Size.Width - button1.Size.Width - 100), NormalDistributor.WeightedRandom(0, this.Size.Height - button1.Size.Height - 100)); }
/// <summary> /// Move mouse cursor to a random position within a rectangle /// </summary> /// <param name="rect">Rectangle</param> /// <param name="speed">Cursor speed</param> public void MoveTo(Rectangle rect, double speed = SpeedDefault) { // keep looping until the cursor is within range while (!rect.Contains(Location)) { // WeightedRandom is not always return values within the given range. MoveTo(NormalDistributor.WeightedRandom(rect.X, rect.Right), NormalDistributor.WeightedRandom(rect.Y, rect.Bottom)); } }