在C#中使用基本表單應用程序時,無法訪問其中的變量。訪問表單變量
因此,與在窗體類我有
public partial class pingerform : Form
{
..
..
private System.Windows.Forms.TextBox textBox2;
public string textBox2Text
{
get { return textBox2.Text; }
set { textBox2.Text = value; }
}
然後在主應用程序,我有
Application.Run(new pingerform());
...
...
pingerform.textBox2Text.text() = str;
,但據我所知,沒有對象的引用。
錯誤1
是所必需的非靜態字段, 方法或屬性的對象引用 'pingerform.textBox2Text.get' C:\用戶\ aaron.street \文件\視覺 工作室11 \ Projects \ PingDrop \ PingDrop \ Program.cs 54 21 PingDrop
所以我認爲我會讓平格窗體類靜態,但它不會讓我這樣做?
錯誤1
無法創建靜態類的實例 'PingDrop.pingerform' C:\用戶\ aaron.street \文檔\ Visual Studio的 11周\項目\ PingDrop \ PingDrop \的Program.cs 21 29 PingDrop
如何訪問表單屬性與出創建窗體的特定實例,
我有一個後臺線程運行,我想定期更新的形式提交文本?
乾杯
亞倫
這會打破。 – wRAR
這是否被認爲是最佳實踐,創建一個窗體的明確實例。那麼爲什麼在Visual Studio中創建模板時使用的方法不這樣做。 – DevilWAH
@DevilWAH這是唯一可能的做法(除了VB或其他瘋狂) – wRAR