0
我做了一個名爲UserControl1的UserControl按鈕,我試圖從模板中更改它的標題(我很喜歡簡單的時鐘設計,但前面有一小步)。如何從另一個cs中的Usercontrol更改標題?
我似乎無法做到這一點。我寫在的UserControl1這段代碼,:
public string Display
{
get { return label1.Text; }
set { label1.Text = value; }
}
然後,我寫這篇文章的形式,在公共類中:
UserControl1.Display = "Title";
它顯示了一個錯誤的「=」號:
Invalid token '=' in class, struct, or interface member declaration.
我有一種感覺我真的很接近,有人可以幫我嗎?
感謝您的幫助,但如果我創建另一個公共無效的那樣,例如:) 公共無效Displaystring({UserControl1.Display =「標題」 ; } 我收到另一個錯誤: 錯誤1非靜態字段,方法或屬性需要對象引用 – Benoo888
錯誤在UserControl1.Display中,它要求提供對象引用。 – Benoo888
@ Benoo888我認爲你必須在當前頁面創建一個UserControl的實例。 'UserControl1 uc = new UserControl1();現在你可以寫uc.Display =「Title」.' –