如何强制秒表 - 从label1.text开始/停止? [英] How to force stopwatch - start/stop from label1.text?

查看:59
本文介绍了如何强制秒表 - 从label1.text开始/停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在练习一个小项目。根据鼠标移动,必须启动或停止秒表。

即,一旦鼠标在里面,然后启动秒表,否则停止。可能吗?

我的代码:aspx页

Hi I 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

推荐答案

没有。这种方式是不可能的...

在ASP.NET服务器和客户端是如此分离,该服务器不知道客户端上的鼠标位置,所以你不能将它用作指标.. 。

您应该学习客户端(JavaScript)编程以在那里创建秒表并在标签的客户端事件(悬停)上停止/启动它...

其他选项是找到具有客户端功能的其他Timer类(不是Microsoft的类)...
No. It is not possible that way...
In ASP.NET server and client are so separated, that server does not know about mouse position on client nothing, so you can not use it as indicator...
You should learn client side (JavaScript) programming to create a stopwatch there and stop/start it on client side events (hover) of the label...
Other option is to find an other Timer class (not the one from Microsoft) with client side capabilities...


这篇关于如何强制秒表 - 从label1.text开始/停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆