2个表格.表格1是登录界面,表格2有秒表.如何切换,但秒表不停止? [英] 2 forms.Form 1 is a log in screen, form 2 has a stopwatch.How to switch between them but the stopwatch wont stop?

查看:36
本文介绍了2个表格.表格1是登录界面,表格2有秒表.如何切换,但秒表不停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表格 1 有一个按钮,可以让您进入表格 2.(按下表格 1 关闭表格 2 显示)

form 1 has a button which gets you to form 2.(When pressed form 1 closes form 2 shows)

form 2 有一个秒表,一旦你按下 form1 中的按钮就会自动启动

form 2 has a stopwatch which automatically starts once you ve pressed the button in form1

表单 2 也有一个按钮,可以让您返回表单 1.(按下表单 2 时会关闭表单 1 显示)

form 2 also has a button which gets you back to form 1.(when pressed form 2 closes form 1 shows)

问题是,当第二次在表单 1 和表单 2 之间切换时,会创建一个新的表单 2 窗口,这意味着秒表会重新启动.

The problem is that when switching btween form 1 to form 2 for the SECOND time a new form 2 window is created and that means that the stopwatch restarts.

我希望能够在表单之间切换,并且秒表从第一次登录开始就不停地工作,并且仅在我终止应用程序时停止

I want to be able to switch between the forms and the stopwatch will work non - stop since the very first log - in and stops only when i terminate the app

我对如何解决这个问题有想法,但我是 C# 新手,所以我不知道如何实现.尽量具体说明你的答案,如果可能的话,给我一些你的想法的编码示例.

I have ideas on how to fix that but im completely new in C# so i dont know how to make that happen.Try to be specific with your answers and give me some coded examples of your thoughts if that s possible.

推荐答案

问题是当你 Close() form2 时,里面的东西被破坏了.因此,您要么需要一个单独的 Thread 用于 StopWatch,或者您可以尝试将表单设置为在未显示时不可见.

The problem is that when you Close() form2, that the stuff in it gets destroyed. So you either need a seperate Thread for your StopWatch or you could try to set the form to invisible while it is not shown.

这篇关于2个表格.表格1是登录界面,表格2有秒表.如何切换,但秒表不停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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