SIGN UP MEMBER LOGIN:    
ARTICLE

Button Chaser Program

Posted by andrew.phillips Articles | Windows Forms C# August 29, 2001
Here is a fun program which causes the user to chase a button around the screen.
Reader Level:
Download Files:
 

Here is a fun program which causes the user to chase a button around the screen. The title bar captures the mouse coordinates and the screen colon changes.

Source Code:

private void MouseMoveHandler(Object sender,MouseEventArgs e)
{
int i;
double d_change;
this.Text = "Mouse Move x-Coordinate = " + e.X.ToString() + " y-Coordinate = " + e.Y.ToString() + " " + s_color;
if(((e.X >= (b_x-2)) && (e.X <= (b_x + b_x_len))) || ((e.Y >= (b_y-2)) && (e.Y <= (b_y + b_y_len))))
{
n_amount = n_amount + 1000;
if (n_amount > 1000000)
n_amount = 1000;
sb_text = "click here and will $" + n_amount.ToString();
b_x = generateRandomNumber.Next() % (600 - b_x_len);
b_y = generateRandomNumber.Next() % (600 - b_y_len);
i = generateRandomNumber.Next() % 140;
d_change = n_amount % 10000;
if (d_change == 0)
{
this.BackColor = color[i];
s_color = color[i].ToString();
}
this.button1.Location = new System.Drawing.Point(b_x, b_y);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(b_x_len, b_y_len);
this.button1.TabIndex = 0;
this.button1.Text = sb_text;
}
try
{
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor