Bonjour,

Soyez indulgent pour un sexagénaire, newbie en C# !
C'est mon premier programme
Je n'ai pas trouvé de livre C# pour les nuls++

J'essaye de faire un programme qui en fonction du click sur 2 boutons va ouvrir 2 forms différentes
pour cela j'utilise une variable b qui sera testé dans le main,

Dans la form1 je donne une valeur à b suivant le bouton cliqué :
Dans la form1, J'ai ce message d'erreur, Pourtant la classe Perso est publique.
Dans la classe Perso je crée un objet b, ma variable

(désolé pour l'affichage du code, quand je prévisualise les tabulations n'apparaissent pas ?)

Error 1 The name 'b' does not exist in the current context

Program.cs

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
namespace MotDePasse
{
    public class Perso
    {    
        public int variables;
    }
 
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
 
        [STAThread]
 
        static void Main()
        {
            Perso b = new Perso();
            b.variables = 0;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            if (b.variables == 0)
            {
                Application.Run(new Form2());
            }
            else
            {
                Application.Run(new Form3());
            }
        }
    }
}

Form1.cs

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace MotDePasse
 
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            //lorsque le bouton est appuyé on ferme la fenetre et affiche fenetre 2        
            b.variables = 0;
            this.Close();
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            //lorsque le bouton est appuyé on ferme la fenetre et affiche fenetre 3  
            b.variables = 1;
            this.Close();
        }
    }
}