如何从表单外部更改图片框显示的图片 [英] How do I changle the picture displayed by a picturebox from outside the form

查看:97
本文介绍了如何从表单外部更改图片框显示的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我想在Windows窗体中更改pictureBox显示的图像时,我会发出如下事件:



Ordinarily, when I want to change the image displayed by a pictureBox from within a Windows form, I fire an event like this:

private: System::Void PicBoxMonton1_DoubleClick(System::Object^  sender, System::EventArgs^  e)
{
    if (this->PicBoxMonton1->Image != Image::FromFile(Glo::m_Empty))
    {
        this->PicBoxMonton1->Image = Image::FromFile(Glo::m_Empty);
        ....
        ....
    }
}



此语法(this-> PicBoxMonton1-当我尝试在单独的 .cpp 文件中写入的函数中执行 if 语句时,>图像)不起作用。
>
我是初学者。

我需要将哪些参数传递给函数?

如何更改中的指令if 声明?



我尝试过:



一切在我有限的经验中。我没有找到一个例子来说明我。


This syntax (this->PicBoxMonton1->Image) doesn't work when I try to execute the if statement from within a function written in a separate .cpp file where all my function are.
I am a beginner.
Which parameters do I need to pass to the function?
How do I change the instruction within the if statement?

What I have tried:

Everything within my limited experience. And I haven't found a single example to illustrate me.

推荐答案

要解决这个问题,你应该声明一个你调用的公共函数从外部。为此,您需要一个指向表单类实例的有效指针。



另一个问题是,调用必须位于应用程序的主线程中。只有当它不在主线程中时才看一下这个答案
To solve the problem you should declare a public function which you call from the outside. For that you need a valid pointer to your form class instance.

Another issue is, that the call must be in the main thread of your app. Only if it is not in the main thread take a look at this answers at stackoverflow.


这篇关于如何从表单外部更改图片框显示的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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