如何在单独的表单中访问其他表单的控件? [英] How to access controls of other forms within a separate form?

查看:112
本文介绍了如何在单独的表单中访问其他表单的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种形式:form1和form2,它们是相同名称空间和相同局部类的一部分.现在我在Form1中有一个按钮(btn1),当我按下此按钮时,必须激活Form2中的计时器(timer1).我正在使用此计时器为Form2中的某些元素设置动画.我该如何做到这一点? (我还公开了计时器.)
如果我在form1中创建了一个form2的新对象,并在单击按钮时尝试启用计时器(form2 frm2 = new form2(); frm2.timer.enable = true;),那么我可以看到计时器在滴答作响,但是动画没有发生.
但是,如果我从form2本身启用计时器,则动画正在发生.
请帮助.

I have two forms : form1 and form2 , which are part of the same namespace and the same partial class. Now i have a button (btn1) in form1 and when i press this button, a timer (timer1) in form2 must be activated. I''m using this timer to animate some elements in form2. How do i accomplish this? (I have also made the timer public.)
If i create a new object of form2 within form1 and try to enable the timer when i click the button (form2 frm2 = new form2(); frm2.timer.enable=true;), then i can see the timer ticking, but the animations are not happening.
However, if i enable the timer from within form2 itself, then the animations are happening.
Pls help. Is there a separate way to invoke the timer?

推荐答案

在form2上创建一个公共属性.此公共财产应有权使用计时器.

然后从form1调用此属性.
Create a public property on form2. This public property should have access to the timer.

Then call this property from form1.


这篇关于如何在单独的表单中访问其他表单的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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