我的思想不知何故陷入了“错误循环”。我不想再用无休止的反复试验浪费时间,所以我最好在这里问:
我有一个 Windows 窗体(.NET,C++),如下所示。这里的简化版只有一个RichTextBox,一个静态成员函数和一个非静态成员函数。从非静态函数“ nonstaticFunc() ”将文本附加到 RichTextBox 可以按预期工作。
但是我怎样才能从静态成员函数“ staticFunc() ”中做到这一点?我尝试了这个论坛中提出的几种关于如何从静态函数调用非静态函数的方法,但不知何故我无法弄清楚如何做到这一点。
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1()
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
protected:
private:
System::ComponentModel::Container ^components;
private: System::Windows::Forms::RichTextBox^ myTextBox;
System::VoidInitializeComponent( System::Void )
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->myTextBox = (gcnew System::Windows::Forms::RichTextBox());
}
public: System::Void nonstaticFunc( System::Void )
{
this->myTextBox->AppendText( L"Append this...\n" );
}
public: static System::Void staticFunc( System::Void )
{
// How do I AppendText here??
// Not working: this->myTextBox->AppendText( L"Append this...\n" );
}
}
感谢每一点帮助!非常赞赏!