Clickable Number Images from Starting out with Visual C# 5th Edition page 113
This is the code I have written:
}
private void pictureBoxOne_Click(object sender, EventArgs e)
{
questionBoxOne.Visible = true;
pictureBoxOne.Visible = false;
showNumber.Text = "";
}
private void questionBoxOne_Click(object sender, EventArgs e)
{
questionBoxOne.Visible = false;
pictureBoxOne.Visible = true;
showNumber.Text = "One";
pictureBoxTwo.Visible = true;
pictureBoxThree.Visible = true;
pictureBoxFour.Visible = true;
pictureBoxFive.Visible = true;
}
private void pictureBoxTwo_Click(object sender, EventArgs e)
{
questionBoxTwo.Visible = true;
pictureBoxTwo.Visible = false;
showNumber.Text = "";
}
private void questionBoxTwo_Click(object sender, EventArgs e)
{
questionBoxTwo.Visible = false;
pictureBoxTwo.Visible = true;
showNumber.Text = "Two";
pictureBoxOne.Visible = true;
pictureBoxThree.Visible = true;
pictureBoxFour.Visible = true;
pictureBoxFive.Visible = true;
}
private void pictureBoxThree_Click(object sender, EventArgs e)
{
questionBoxThree.Visible = true;
pictureBoxThree.Visible = false;
showNumber.Text = "";
}
private void questionBoxThree_Click(object sender, EventArgs e)
{
questionBoxThree.Visible = false;
pictureBoxThree.Visible = true;
showNumber.Text = "Three";
pictureBoxOne.Visible = true;
pictureBoxTwo.Visible = true;
pictureBoxFour.Visible = true;
pictureBoxFive.Visible = true;
}
private void pictureBoxFour_Click(object sender, EventArgs e)
{
questionBoxFour.Visible = true;
pictureBoxFour.Visible = false;
showNumber.Text = "";
}
private void questionBoxFour_Click(object sender, EventArgs e)
{
questionBoxFour.Visible = false;
pictureBoxFour.Visible = true;
showNumber.Text = "Four";
pictureBoxOne.Visible = true;
pictureBoxTwo.Visible = true;
pictureBoxThree.Visible = true;
pictureBoxFive.Visible = true;
}
private void pictureBoxFive_Click(object sender, EventArgs e)
{
questionBoxFive.Visible = true;
pictureBoxFive.Visible = false;
showNumber.Text = "";
}
private void showNumber_Click(object sender, EventArgs e)
{
showNumber.Text = "";
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void questionBoxFive_Click(object sender, EventArgs e)
{
questionBoxFive.Visible = false;
pictureBoxFive.Visible = true;
showNumber.Text = "Five";
pictureBoxOne.Visible = true;
pictureBoxTwo.Visible = true;
pictureBoxThree.Visible = true;
pictureBoxFour.Visible = true;
}
private void resetButton_Click(object sender, EventArgs e)
{
Application.Restart();
}
}
}
This is what I want to accomplish:
Only ONE PictureBox control can display a number and number name at any given time. Therefore, if the user clicks on a different PictureBox control displaying a question mark, the other number PictureBox control(s) should be changed to the question mark PictureBox control and the Label control displaying the number name should display the newly selected number name.
Please assist me on how to accomplish this.
Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.
Download code, extract it using 7zip,winrar etc. open .sln file with visual studio. Run the program.
Download Code:
https://drive.google.com/open?id=1tGU5McbApNeSfK0s9gzjiO6PO1Hjk3ld
Code:
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 PictureBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBoxOne_Click(object sender, EventArgs
e)
{
reset();
pictureBoxOne.Image = Properties.Resources._1;
pictureBoxOne.Refresh();
showNumber.Text = "One";
}
private void reset()
{
pictureBoxOne.Image = Properties.Resources.question;
pictureBoxOne.Refresh();
pictureBoxTwo.Image = Properties.Resources.question;
pictureBoxTwo.Refresh();
pictureBoxThree.Image = Properties.Resources.question;
pictureBoxThree.Refresh();
pictureBoxFour.Image = Properties.Resources.question;
pictureBoxFour.Refresh();
pictureBoxFive.Image = Properties.Resources.question;
pictureBoxFive.Refresh();
showNumber.Text = "";
}
private void pictureBoxTwo_Click(object sender, EventArgs
e)
{
reset();
pictureBoxTwo.Image = Properties.Resources._2;
pictureBoxTwo.Refresh();
showNumber.Text = "Two";
}
private void pictureBoxThree_Click(object sender, EventArgs
e)
{
reset();
pictureBoxThree.Image = Properties.Resources._3;
pictureBoxThree.Refresh();
showNumber.Text = "Three";
}
private void pictureBoxFour_Click(object sender, EventArgs
e)
{
reset();
pictureBoxFour.Image = Properties.Resources._4;
pictureBoxFour.Refresh();
showNumber.Text = "Four";
}
private void pictureBoxFive_Click(object sender, EventArgs
e)
{
reset();
pictureBoxFive.Image = Properties.Resources._5;
pictureBoxFive.Refresh();
showNumber.Text = "Five";
}
}
}
Sample Output:
Get Answers For Free
Most questions answered within 1 hours.