C++ : 如何访问Form1中创建的对象?
我是 C++ 新手,我使用的是 VC++ 2008,我创建了一个带有 GUI 设计的带有 pictureBox 的表单,位于 Form1.h 中。
为了代码稳定性,我试图将 gui 和处理类分开,所以我在 process.h 中创建了一个新类,其中包含更改 pictureBox 中图像的代码,问题是我无法从 process.h 访问 pictureBox 对象,因为它位于不同的班级。
笔记 : form 的类名是命名空间 try 内的 Form1, 进程的类名是 processImage
我试图在类 Form1 中创建一个名为 setImage() 的 setter 函数来设置 imageBox obj 的图像路径,但我无法创建 Form1 的对象来调用该函数,因为 Form1 类未知。请注意,我已尝试#include“Form1.h”,但它仍然未知。
我的问题有什么解决办法吗?
感谢您的帮助..
i am new in C++, i'm using VC++ 2008, i have created a form with pictureBox inside with gui design, located in Form1.h.
for code stability, i'm trying to separate beetween gui and processing classes, so i made a new class in process.h which contain code to change image in the pictureBox, the problem is that i cant access pictureBox object from process.h because it's located in different class.
note :
the classname of form is Form1 inside namespace try,
the classname of process is processImage
i have tried to make a setter function named setImage() in class Form1 to set image path of imageBox obj, but i cant make object of Form1 to call that function because Form1 class is not known. for note i have tried to #include "Form1.h" but it still unknown.
is there any solution for my problem?
thanks for your help..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建类ProcessImage,并将该类的一个对象作为Form1类的成员变量。在 ProcessImage 类中创建 setImage 公共方法。每当图片框中的图像更新时,调用此方法。
Create the class ProcessImage and make an object of this class a member variable of the Form1 class. Create a setImage public method in the ProcessImage class. Whenever the image in the picture box is updated, call this method.
我不确定我是否能理解你的问题,但这里有一些提示。
您说您包含了 Form1.h 但 Form1 仍然不可见。当 A 包含 B 且 B 包含 A 时,可能会出现问题,可以通过前向声明来解决。确保您没有忘记名称空间。
啊:
啊:
I'm not sure if I could understand your problem, but here's few hints.
You say that you include Form1.h but Form1 is still not visible. It could be the problem when A include B and B include A, that could be solved with forward declarations. Make sure that you don't forget the namespaces.
A.h:
B.h: