Provide the complete c# code
Unit a single-thread.
After the form loads. Show a filled 50 pixel by 50 pixel square at 200,200 coordinates.The application move +5 pixels in y direction every a seconds. N is random number of 1-10. Use different random number for each delay. Random movements stop when user press “X” key. Assume infinitely large drawing area.
Show new position after each move by printing the coordinates on drawing area or using a dialog window or a label or textbox.
New Random(). Nextmax(Maximus_value) FillRectangle(…) SolidBrush. These method can be used in the code
Design
Coding:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Cordinates
{
public partial class Form1 : Form
{
int N;
public Form1()
{
InitializeComponent();
}
private void
Form1_Load(object sender, EventArgs e)
{
rectangleShape1.Location = new Point(200, 200);//location of
cordinates set
timer1.Start();//start timer
}
private void
timer1_Tick(object sender, EventArgs e)
{
Random rnd = new Random();//for generating random Number
N = rnd.Next(10);//generate ranom number
rectangleShape1.Location = new Point(rectangleShape1.Location.X+N,
rectangleShape1.Location.Y+N);
txtcordinates.Text = "X:" + rectangleShape1.Location.X + " Y:" +
rectangleShape1.Location.Y;
}
private void
Form1_KeyPress(object sender, KeyPressEventArgs e)
{
txtcordinates_KeyPress(sender, e);
}
private void
txtcordinates_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.X)
{
timer1.Stop();
MessageBox.Show("timer is stop");//message if you
txtcordinates.Text = "X:" + rectangleShape1.Location.X + " Y:" +
rectangleShape1.Location.Y;
}
}
}
}
output:
if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........
Provide the complete c# code Unit a single-thread. After the form loads. Show a filled 50 pixel by 50 pixel square at 200,200 coordinates.The application move +5 pixels in y direction every a seconds....