【发布时间】:2020-04-04 21:34:24
【问题描述】:
我已经看到它在 C# 中工作,但在 Visual C++ 2015 中却没有
System::Windows::Forms::Label^ mylabel= (gcnew System::Windows::Forms::Label());
mylabel->Name = L"pole";
mylabel->Text = "Hello";
this->Controls->Add(mylabel);
请注意,mylabel 在这里是一个临时变量。 现在代码适用于 C#
Control cc = this.Controls.Find("pole", true).First();
cc.text="New";
我已经尝试过了,因为没有 .First() 或 ->first(),
Control^ x = this->Controls->Find(L"pole", true);
肯定会显示错误
`cli::array<System::Windows::Forms::Control ^, 1> ^" cannot be used to initialize an entity of type "System::Windows::Forms::Control ^`"
如何在运行时将该对象作为控件?
【问题讨论】:
-
array<Control^>^ x = ....Winforms 不保证控件名称是唯一的,因此您会得到一个数组。希望它是数组中的第一个元素,x[0]。
标签: visual-studio visual-c++ c++-cli