To keep it simple. (为了简单起见。) In VS2019 I have created 1 form (frm1) with dimensions 500x500 and a button. (在VS2019中,我创建了1个尺寸为500x500的表单(frm1)和一个按钮。) I create a Windows.Forms.Timer timer1, set its interval to 10. Upon pushing the button I enable timer1 and tell frm1 to move to the Left for 500px (equal to its width) (我创建一个Windows.Forms.Timer timer1,将其间隔设置为10。按下按钮后,我启用timer1并告诉frm1向左移动500px(等于其宽度))
namespace WindowsFormsApp4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Left += 10;
if (this.Left > 500)
{
timer1.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
}
However, when I run the code frm1 only moves to the left 10px as if the timer has only ticked once. (但是,当我运行代码frm1时,它只会向左移动10px,就好像计时器只被勾选了一次一样。) I have to add something like >= 1000 to get it to cover the whole length of frm1 (500px wide), which doesnt make sense. (我必须添加> = 1000之类的内容才能覆盖frm1(宽500px)的整个长度,这没有任何意义。) Any ideas?? (有任何想法吗??)
ask by Dimitris Platis translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…