• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Help with c# app for beginner please

Mike_1

New Coder
Hi all,

I am trying to build a desktop app for my own personal use. I am a total beginner at coding but have learnt how to get button click to show image in picturebox, and a few other things.
What I need help with at the moment is how to get an image to show after clicking consecutive buttons, i.e click button1 then 2 then 3, and only after clicking all buttons in that order image shows in picture box.
Thank you in advance for any help at all with this:)
 

Regy

New Coder
I thought I'd try and work this one out. I'm not an expert but this code seems to work.
C#:
namespace csharptest
{

    public partial class Form1 : Form
    {
    int buttonsequence = 0;

        public Form1()
        {
        InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
        buttonsequence = 1;
        MessageBox.Show("Button1 pressed.");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (buttonsequence == 1)
            {
            buttonsequence = 2;
            MessageBox.Show("Button1 pressed and then Button2 pressed.");
            }
            else
            buttonsequence = 0;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (buttonsequence == 2)
            {
            MessageBox.Show ("Show the image!");
            buttonsequence = 0;
            }
            else
            buttonsequence = 0;
        }
    }
}
 

Top