질문하고 싶습니다. 이 코드를 얻었고 내 의도는 동적 레이블을 만들어 다른 레이블 위에 레이블을 겹치지 않고 값을 새로 고칩니다.동적 라벨의 C# refresh 값
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();
}
새 레이블 매번 만들 필요가 없습니다. 타이머를 만들고 단일 레이블에 값을 표시하고 싶습니까? – MethodMan
Can not just lbl.Text = string.Empty; 삭제하려면 lbl.Text = newValue; 설정하려면 lbl.Invalidate; 강제로 다시 그리기? – Kevin