例如,我为 timer1.interval
设定了 5000
。 我想知道在计时器计时之前有多少间隔还剩下。 我该怎么做?
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
例如,我为 timer1.interval
设定了 5000
。 我想知道在计时器计时之前有多少间隔还剩下。 我该怎么做?
如何检查计时时间?
您无法。 定时器班无法提供任何方法检查定时器应点火前的剩余时间。 您所能做的就是跟踪计时器最后一次发射的时间, 并计算下个计时器前的剩余时间 。
DateTime MainTimer_last_Tick = DateTime.Now;
System.Windows.Forms.Timer timer_Calc_Remaining;
timer_Calc_Remaining.Enabled = true;
timer_Calc_Remaining.Interval = 100;
timer_Calc_Remaining.Tick += new System.EventHandler(this.timer_Calc_Remaining_Tick);
主计时器开始或选中时 :
timer_Main.Enabled = true;
MainTimer_last_Tick = DateTime.Now;
private void timer_Calc_Remaining_Tick(object sender, EventArgs e)
{
int remaining_Milliseconds = (int)(MainTimer_last_Tick.AddMilliseconds(timer_Main.Interval).Subtract(DateTime.Now).TotalMilliseconds);
.../*
int newValue = (timer_Main.Interval -remaining_Milliseconds) ;
progressBar1.Maximum = timer_Main.Interval+1;
progressBar1.Value = newValue ;*/
}
您可以使用一个间隔为1000( 毫秒) 的替代计时器。 我不认为一米的间隔是一个真正的选项, 因为这样会使系统压力太大, 而且不可靠 。
每次这个计时器折叠时, 您可以检查秒数( 总是千位数吗? ), 然后从( 或使用 modulo) 5000 中减去 。
但我不能:
s 因为没有标志的少出现在 等同的标志之前 而不是相反的圆形
if (timer1.Interval <= 5000)
{
//do something
}
您正在使用 Interval, 该属性将不会被更改( 总是 5000, 所以检查它是否小于 5000 是毫无意义的 ) 。 另外, 如果该代码在 < code>Timer1_ Tick < / code > 函数中, 它将不会有效 。 但是, 您需要的代码是 :
if (timer1.Interval <= 5000)
{
//do something
}
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...