【问题标题】:Visual Studio Image type is not allowed不允许使用 Visual Studio 图像类型
【发布时间】:2021-09-24 01:36:20
【问题描述】:

我正在尝试根据单击更改图像 (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++/CLI 项目中吗? en.wikipedia.org/wiki/C%2B%2B/CLI
  • @RetiredNinja 是的
  • FromFile 是一个静态方法,所以在调用它时必须使用::Image::FromFile("...

标签: c++ image visual-studio visual-c++ c++-cli


【解决方案1】:

FromFile 是一个静态方法,C++ /CLI 语法要求使用:: 进行静态方法调用。所以在这种情况下,调用应该如下所示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多