首页 > 解决方案 > 不允许使用 Visual Studio 图像类型

问题描述

我正在尝试根据单击更改图像(Visual Studio C++)。我的代码:

private: System::Void FirstChannelButton_Click_1(System::Object^ sender, System::EventArgs^ e) {
    FirstChannelButton->Image = Image.FromFile("C:\Users\Username\source\repos\Project\ChOne.png");
}

与该人在这里尝试做的事情完全相同 C++ Change image based on a click (Visual Studio C++)

但我得到错误:不允许类型名称和'System::Drawing::Image':非法使用这种类型作为表达式。

标签: c++imagevisual-studiovisual-c++c++-cli

解决方案


FromFile is a static method and C++ /CLI syntax requires to use :: for static method calls. So in this case the call should look next:

FirstChannelButton->Image = Image::FromFile("...")

推荐阅读