[错误]将状态赋予另一个表单上的复选框:/ [英] [Error] Giving a state to a checkbox on another form :/

查看:86
本文介绍了[错误]将状态赋予另一个表单上的复选框:/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我一直在做我的项目,但是当我尝试在另一个表单上写一个复选框时



首先编写了这段代码,但确实注意到了错误:



Hello, I''ve been doing my project but when I try to write the state a checkbox on another form

First wrote this code but did note that error:

Form2::checkBox1->Checked=true;





错误:

来自非静态成员的推荐必须相对于特定对象



所以我决定在谷歌搜索来扩展我的知识,我找到了这段代码,但两者都没有用我:/ ..:





Error:
A referral from a non-static member must be relative to a specific object

So I decided to search in google to expand my knowledge and I found this code but neither has worked for me :/ ..:

Form2 ^formA = gcnew Form2();

formA::checkBox1->Checked=true







错误1错误C2065:''formA'':识别号没有声明



错误2错误C2065:''r'':识别没有声明





我还发现了另一个代码将formA替换为frm2但也由同一错误引起。 :/



一些解决方案?



提前致谢

推荐答案

这是关于表单的热门问题合作。最强大的解决方案是在表单类中实现适当的接口,并传递接口引用而不是引用Form的整个实例。有关更多详细信息,请参阅我以前的解决方案:如何以两种形式复制列表框之间的所有项目 [ ^ ]。



另请参阅此处的其他解决方案讨论。如果应用程序足够简单,解决方案就像在一个表单中声明一些 internal 属性并将对一个表单的实例的引用传递给另一个表单的实例一样简单形成。对于更复杂的项目,这种违反严格封装的样式和松散耦合可能会增加代码的意外复杂性并引发错误,因此封装良好的解决方案将是优惠。



另请参阅:

http://en.wikipedia.org/wiki/Accidental_complexity [ ^ ],

http://en.wikipedia.org/wiki/Loose_coupling [ ^ ]。



使用C ++和C ++ / CLI,由于缺少部分类,我在过去的答案中使用部分类的建议是不适用的;请忽略这一部分。



-SA
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

With C++ and C++/CLI, due to lack of partial classes, my advice of using partial classes found in my past answers is inapplicable; just ignore this part.

—SA


除了解决方案1,还有一些在某些情况下可能有用的替代方案。



在简单的情况下,第二种形式可能有1或2个属性。



如果有很多变化,可以使用静态Show方法(如 MessageBox :: Show )调用者。



如果第二种形式很复杂,那么一个想法可能就是拥有一个代表数据的类(如在模型 - 视图 - 控制器模式中)并且是能够从表单中设置或获取数据对象。
In addition to solution 1, there are some alternatives that might be usefull in some cases.

In simple case, the second form might have 1 or 2 properties.

A static Show method (like MessageBox::Show) could be used if there are a lot of varied caller.

If the second form is complex, then an idea might be to have a class that represent the data (as in Model-View-Controler pattern) and be able to set or get the data object from the form.


原谅,但不太了解你在其他问题中的意思。



他们可以给我一个代码来帮助我完成我的项目吗?
Forgive, but do not understand much of what you meant in your other question.

They could give me a code to help me finish my proyect?


这篇关于[错误]将状态赋予另一个表单上的复选框:/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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