0
我有一個窗體(Form1.h
)Button
和TextBox
。表單初始化時,TextBox
爲空。點擊按鈕後,將調用表單外的方法,並應更新TextBox
。我如何從非形式課程更新TextBox
?下面是我的示例代碼:從窗體外的公共方法更新文本框
// Form1.h
private: System::Void findResultButton_Click(System::Object^ sender, System::EventArgs^ e) {
FirstResults* firstResults = new FirstResults();
firstResults->findResult();
}
// FirstResults.cpp
void FirstResults::findResult() {
// do some calculations here and find result.
// write the result value to a .txt file.
// Update TextBox in Form1.h with result value.
}
不是一個C++專家,但是你可以簡單地將引用傳遞給你的函數,然後在那裏更新文本? – Steve
從該函數返回一個'List ^'。或者將它傳遞給一個委託,這樣可以進行回調。類似的東西。 –
@HansPassant謝謝。我已經與代表一起嘗試過了,現在我正在尋找方法來在unmanged類中聲明託管代表。 –