我正在使用此代码为表单添加标签,但是当我关闭表单时,它们都会消失。有没有办法保存标签或创建每次都会加载并恢复标签的文本文档?
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
答案 0 :(得分:1)
要让它们持久存在,您需要在设计时从工具箱中添加它们。
请查看此说明:
http://www.homeandlearn.co.uk/csharp/csharp_s1p6.html
或者,您需要拥有一个配置文件,您可以在每次添加控件时保存该配置文件,并使用适当的属性,然后您可以在加载表单时从配置文件中重新创建这些文件。
(我假设您使用的是Winforms?)