views:

95

answers:

1

HI, Just ran into a problem. How to I change a picturebox's picture from within a different header file.

If I do it in the same .h file as the Form I am working on I use:

sq1->Image = bi; (which loads in a bitmap)

but when I do it from another header (i've included the correct header file), I get "sq1 is an undeclared identifier" and "left of '->image' must point to a class/struct/union/generic"

What I'm looking for is something like

Form1::sq1->Image = bi;

Basically I just want to point the program to change picturebox from another location....Is this possible? How can I do this?

Cheers!

A: 

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.

Georg Fritzsche