从 parent 标签获取计时器倒计时
get timer countdown from parent label
我有一个倒计时,它输出到主窗体上的标签,我想从主窗体弹出倒计时到 child 窗体,因为 child 窗体将能够保持在所有其他 windows 之上(对于游戏) 我无法更新 child 标签上的倒计时。当我按下弹出按钮时,我只得到第二个。
这是在主窗体上
private void tmrMain_Tick(object sender, EventArgs e)
{
TimerSeconds = TimerSeconds - 1;
if (TimerSeconds == 0)
{
tmrMain.Stop();
if (chbxPlaySound.Checked)
{
System.Media.SystemSounds.Exclamation.Play();
}
if (chbxRepeat.Checked)
{
btnStartTimer.PerformClick();
}
}
string dis_seconds = Convert.ToString(TimerSeconds);
//
// lblTimer is the label that shows the countdown seconds
//
lblTimer.Text = dis_seconds;
}
这是我在主窗体上的弹出按钮
private void btnPopOut_Click(object sender, EventArgs e)
{
PopTimer ShowTimer = new PopTimer(TimerSeconds);
ShowTimer.Show(this);
}
这是我的 child 表格
public partial class PopTimer : Form
{
public PopTimer(int countTimer)
{
InitializeComponent();
//string dis_seconds = Convert.ToString(TimerSeconds);
lblPopTimer.Text = Convert.ToString(countTimer); ;
}
}
您的 PopTimer 表单需要一个可访问的方法,如下所示:
public void SetCountdown(int value) {
lblPopTimer.Text = value.ToString();
}
然后你的 PopTimer 需要可访问,所以移动声明:
private PopTimer showTimer = null;
private void btnPopOut_Click(object sender, EventArgs e)
{
showTimer = new PopTimer(timerSeconds);
showTimer.Show(this);
}
然后在您的报价事件中:
if (showTimer != null) {
showTimer.SetCountdown(timerSeconds);
}
我有一个倒计时,它输出到主窗体上的标签,我想从主窗体弹出倒计时到 child 窗体,因为 child 窗体将能够保持在所有其他 windows 之上(对于游戏) 我无法更新 child 标签上的倒计时。当我按下弹出按钮时,我只得到第二个。
这是在主窗体上
private void tmrMain_Tick(object sender, EventArgs e)
{
TimerSeconds = TimerSeconds - 1;
if (TimerSeconds == 0)
{
tmrMain.Stop();
if (chbxPlaySound.Checked)
{
System.Media.SystemSounds.Exclamation.Play();
}
if (chbxRepeat.Checked)
{
btnStartTimer.PerformClick();
}
}
string dis_seconds = Convert.ToString(TimerSeconds);
//
// lblTimer is the label that shows the countdown seconds
//
lblTimer.Text = dis_seconds;
}
这是我在主窗体上的弹出按钮
private void btnPopOut_Click(object sender, EventArgs e)
{
PopTimer ShowTimer = new PopTimer(TimerSeconds);
ShowTimer.Show(this);
}
这是我的 child 表格
public partial class PopTimer : Form
{
public PopTimer(int countTimer)
{
InitializeComponent();
//string dis_seconds = Convert.ToString(TimerSeconds);
lblPopTimer.Text = Convert.ToString(countTimer); ;
}
}
您的 PopTimer 表单需要一个可访问的方法,如下所示:
public void SetCountdown(int value) {
lblPopTimer.Text = value.ToString();
}
然后你的 PopTimer 需要可访问,所以移动声明:
private PopTimer showTimer = null;
private void btnPopOut_Click(object sender, EventArgs e)
{
showTimer = new PopTimer(timerSeconds);
showTimer.Show(this);
}
然后在您的报价事件中:
if (showTimer != null) {
showTimer.SetCountdown(timerSeconds);
}