ich möchte eine Frage stellen. Ich habe diesen Code und meine Absicht besteht darin, mein dynamisches Label so zu gestalten, dass der Wert aktualisiert wird, ohne dass ein Etikett auf einem anderen gestapelt wird.C# Aktualisierungswert auf einem dynamischen Etikett
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 refresh_label
{
public partial class Form1 : Form
{
Int64 num1 = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Timer t1 = new Timer();
t1.Interval = 1;
t1.Tick += new EventHandler(lbl_refresh);
t1.Enabled = true;
Label lbl = new Label();
lbl.Text = num1.ToString();
this.Controls.Add(lbl);
}
private void lbl_refresh(object sender, EventArgs e)
{
num1++;
}
}
}
//on this one it's working but staking labels. is there a way to refresh the label without staking it and then clear it? thank you for your time.
private void Form1_Load(object sender, EventArgs e)
{
Timer t1 = new Timer();
t1.Interval = 1;
t1.Tick += new EventHandler(lbl_refresh);
t1.Enabled = true;
}
private void lbl_refresh(object sender, EventArgs e)
{
num1++;
Label lbl = new Label();
lbl.Text = num1.ToString();
this.Controls.Add(lbl);
lbl.BringToFront();
}
für den Anfang gibt es keine Notwendigkeit, ein neues Etikett jedes Mal zu erstellen. Möchten Sie nur einen Timer erstellen und die Werte in einem einzelnen Label anzeigen? – MethodMan
Kannst du nicht einfach lbl.Text = string.Empty; zu löschen, lbl.Text = newValue; einstellen, lbl.Invalidate; erzwingen Neuzeichnen? – Kevin