0

你好,刚刚遇到问题。如何从不同的头文件中更改图片框的图片。

如果我在与我正在处理的表单相同的 .h 文件中执行此操作,我将使用:

sq1->图像=bi;(在位图中加载)

但是当我从另一个头文件中执行此操作时(我已经包含了正确的头文件),我得到“sq1 是一个未声明的标识符”并且“'-> image' 的左侧必须指向一个类/结构/联合/通用”

我正在寻找的是类似的东西

Form1::sq1->Image = bi;

基本上我只想指出程序从另一个位置更改图片框....这可能吗?我怎样才能做到这一点?

干杯!

4

1 回答 1

0

First off, definitions usually belong into source files (e.g. .cpp) and header file (e.g. .h) only contain the declarations.

Usually you add methods to your class to allow other parts of the program to perform operations on it.

Without knowing what types you are using, you could add something like this to the class' declaration:

class Form {
public:
    // ...
    void setImage(const Bitmap& b);
};

... add the definition to source file:

void Form::setImage(const Bitmap& b) {
    // ...
    sq1->Image = b;
    // ...
}

Then you can use it from outside of the class:

myForm.setImage(bmp);

As this is a rather basic problem, i suggest working through an introductory book first before jumping straight into GUI frameworks.

于 2010-02-08T01:14:48.703 回答