本文介绍了如何强制秒表 - 从label1.text开始/停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在练习一个小项目。根据鼠标移动,必须启动或停止秒表。
即,一旦鼠标在里面,然后启动秒表,否则停止。可能吗?
我的代码:aspx页
HiI am practicing a small project. According to mouse movements, the stop watch has to be started or stop.
ie, once the mouse is inside then start the stopwatch otherwise stop. Is it possible?
my codes: aspx page
<div id="Divn1" onmousemove="MyNewFunction(event)" onmouseout="ClearCoor()" style="width:99%; height:99%; border:solid;background-color:white; position:absolute;">
<p id="Demo1"></p>
<asp:Label ID="Label2" runat="server" Font-Size="XX-Large"></asp:Label>
<div id="Divn2" style="width:50px;height:50px;border-radius:50%;background-color:brown; position:absolute; top:45%; margin-left:47%;">
</div>
<asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Font-Size="XX-Large"></asp:Label>
<asp:Timer ID="tm1" Interval="1000" runat="server" ontick="tm1_Tick" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tm1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
然后是aspx.cs
And then aspx.cs
public static Stopwatch sw;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sw = new Stopwatch();
sw.Start();
}
}
protected void tm1_Tick(object sender, EventArgs e)
{
long milsecs = sw.Elapsed.Milliseconds;
if (Label2.Text.Trim().Length > 0)
{
Label1.Text = DateTime.Now.ToString("00:ff");
}
sw.Stop();
//Label1.Visible = false;
}
谢谢
我尝试了什么:
试图在鼠标移动时开始观察
Thanks
What I have tried:
Tried to start watch while the mouse moving
推荐答案
这篇关于如何强制秒表 - 从label1.text开始/停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!