Ich habe den folgenden Code. Es ist ein Formular mit einem einzigen Textfeld darauf. Wenn ich myTimer_Tick
nicht statisch mache, dann funktioniert es gut - warum?Warum macht statische Fehler beim Versuch, Textbox-Text zu aktualisieren
namespace Ariport_Parking
{
public partial class AirportParking : Form
{
//instance variables of the form
static Timer myTimer;
public AirportParking()
{
InitializeComponent();
keepingTime(5000);
txtMessage.Text = "hello";
}
//method for keeping time
public void keepingTime(int howlong) {
myTimer = new Timer();
myTimer.Enabled = true;
myTimer.Tick += new EventHandler(myTimer_Tick);
myTimer.Interval = howlong;
myTimer.Start();
}
static void myTimer_Tick(Object myObject,EventArgs myEventArgs){
myTimer.Stop();
txtMessage.Text = "hello world";
}
}
}
erst uns sagen, warum Sie es statisch sein? – Reniuz
Was funktioniert nicht, wenn * es * eine statische ist? – Tigran
Was ist der Fehler? –