ARTICLE

Tricky Game in C#

Posted by Priyank Patel Articles | Windows Forms C# September 28, 2010
In this article I will show you a tricky game using some mouse events.
Reader Level:
Download Files:
 

Introduction:

This is tricky game using some mouse events.

Step 1:

Add a form in application and make it borderStyle property none.

Step 2:

Add a picturebox and two buttons in the form.

1.gif

Step 3:

int x, y;
bool quit = false;
bool win =false;

private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
    if (quit == false && win == false)
    {
        /*
        When you take mouse over the picturebox randmoly two value generated
        And it is different every time..and that two value assign to x and y which is  
        use to set picture at different location whenever you take mouse over the picture.
        */
        x = Convert.ToInt32(Microsoft.VisualBasic.VBMath.Rnd() * ((this.ClientSize.Width) - 50));
        y = Convert.ToInt32(Microsoft.VisualBasic.VBMath.Rnd() * ((this.ClientSize.Height) - 60));
        pictureBox1.Location = new System.Drawing.Point(x, y);
    }
}
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
    win = true;
    pictureBox1.Image = global::fungame_clickMe.Properties.Resources.winner;
    pictureBox1.Location = new System.Drawing.Point(200, 180);
    pictureBox1.Size = new System.Drawing.Size(200, 200);
}
private void button1_Click(object sender, EventArgs e)
{
    this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
    quit = true;
    pictureBox1.Image = global::fungame_clickMe.Properties.Resources.loser;
    pictureBox1.Location = new System.Drawing.Point(200, 180);
    pictureBox1.Size = new System.Drawing.Size(200,200);
}

Login to add your contents and source code to this article
post comment
     

Go to the form properties. find the fromborder property and set it none .. that's it.

Posted by Priyank Patel May 19, 2011

thanx for this funny game but , how can i make forms borderStyle property none..?? regards

Posted by zainab h May 05, 2011

no need to add any namespace...

Posted by Priyank Patel Jan 10, 2011

Which namespace we have to use here...?

Posted by Rishi Khetan Jan 09, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter