-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
4

1 回答 1

1

要使它们持久化,您需要在设计时从工具箱中添加它们。

看看这个以获取说明:

http://www.homeandlearn.co.uk/csharp/csharp_s1p6.html

或者,您需要在每次添加控件时保存一个具有适当属性的配置文件,然后您可以在表单加载时从配置文件中重新创建这些配置文件。

(我假设您使用的是 Winforms?)

于 2013-10-30T17:06:38.413 回答