C # simulates MSN form jitter

Source: Internet
Author: User

C # simulates MSN form jitter

Form jitter is an interesting thing, let's take a look at how it works.
It is actually generating a random number and then changing the coordinates of the upper-left corner of the form.
I use the loop to make, actually can use the timer to control.

I split the jitter into two types of jitter:
1. Generate random numbers, change the upper-left coordinate of the form, and immediately restore the form's sitting-up corner coordinates to continue the loop.
2. Generate random numbers, change the upper-left corner of the form, and then immediately restore the form's upper-corner coordinates after the loop is complete.

The core code is as follows:


The first type of jitter
private void Button1_Click (object sender, EventArgs e)
{
int RECORDX = this.            Left; Save the X-coordinate of the upper-left corner of the original form
int Recordy = this.             Top; Save the y-coordinate of the upper-left corner of the original form

Random random = new random ();

for (int i = 0; i <; i++)
{
int x = random. Next (RAND);
int y = random. Next (RAND);
if (x% 2 = = 0)
{
This. left = this. Left + x;
}
Else
{
This. left = this. Left-x;
}
if (y% 2 = = 0)
{
This. Top = this. Top + y;
}
Else
{
This. Top = this. Top-y;
}

This.            left = RECORDX; Restores the x-coordinate of the upper-left corner of the original form
This.             Top = Recordy; Restores the y-coordinate of the upper-left corner of the original form
}

}


The second type of jitter
private void Button2_Click (object sender, EventArgs e)
{
int RECORDX = this. Left;
int Recordy = this. Top;
Random random = new random ();
for (int i = 0; i <; i++)
{
int x = random. Next (RAND);
int y = random. Next (RAND);
if (x% 2 = = 0)
{
This. left = this. Left + x;
}
Else
{
This. left = this. Left-x;
}
if (y% 2 = = 0)
{
This. Top = this. Top + y;
}
Else
{
This. Top = this. Top-y;
}
System.Threading.Thread.Sleep (1);
}
This. left = RECORDX;
This. Top = Recordy;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.