Question

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....

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Design

Form1.cs [Design] X XForm1.cs Form1 Textbox id-txtcordinates rectangleShapelid: rectangleShapel Timer :timer1 timer1

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:

Form1 rag to of cordinates set X:294 Y:294 wn.X+N, rectangleshapel . Location . Y+N); :rectangleShape1.Location.Y; ress X he. , Continue Debug - A, 11 . Y r xx Stack Frame: Form1 X:227 Y:227 ttcordinates_KeyPress(object sender, KeyPressEventArgs e)Form1 of cordinates set X:209 Y:209 ion.X+N, rectangleShape1.Locati Y: + rectangleShape1.Location

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.........

Add a comment
Know the answer?
Add Answer to:
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....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT