-3
我使用此代碼爲我的表單添加標籤,但是當我關閉表單時,它們全部消失。有沒有辦法保存標籤或創建一個每次都會加載並恢復標籤的文本文檔?保存在運行時創建的標籤
Private x As Integer = 12
Private y As Integer = 180
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lbl As New label
lbl.Size = New System.Drawing.Size(159, 23) 'set your size
lbl.Location = New System.Drawing.Point(x, y) 'set your location
lbl.Text = (TextBox1.Text) 'set your name
Me.Controls.Add(lbl) 'add your new control to your forms control collection
x += 10 'arbitrary value, you could adjust y, too
End Sub
創建一個自定義類來容納Size(),Location()和Text()。沒有將該類的實例添加到List()。使用XmlSerializer將列表保存到XML文件。反轉該過程以在表單打開時放回標籤。 –
這裏是一個例子:http://stackoverflow.com/a/19143430/1070452 – Plutonix