Bonjour,

J'ai une petite appli à faire en C#, ici je voudrais fermer mon formulaire à la fin d'un Timer.

Mon timer fonctionne, puisque je l'ai testé en remplaçant par et ça marche.

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
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 WindowsFormsApplication1
{
    public partial class Test : Form
    {
        public System.Timers.Timer timer;
 
        public Test()
        {
            InitializeComponent();
 
            timer = new System.Timers.Timer();
            timer.Interval = 10000;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Enabled = true;
            timer.Start();
        }
 
        private void timer_Elapsed(object source, EventArgs e)
        {
            Test.Close();
        }
    }
}
L'erreur est au niveau de la ligne
Une référence d'objet est requise pour la propriété, la méthode ou le champ non statique 'System.Windows.Forms.Form.Close()'.
Merci d'avance :/