0
我正在使用此代碼從文件sQue.txt創建GroupBox讀取,並且我正在填充CheckedListBox從文件sObj.txt讀取。當表單加載時,會創建多個GB(基於來自sQue.txt的條目數量),並且在每個GB中都包含一個CLB和來自sObj.txt的項目。這裏是工作代碼:如何保存動態Groupbox&Checkedlistbox項目
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim NewForm2 As New Form2
NewForm2.Show()
Dim sObj() As String = File.ReadAllLines("C:\temp\sQue.txt")
Dim sQue() As String = File.ReadAllLines("C:\temp\sObj.txt")
For Each s As String In sObj
Me.Controls.Add(MakeNewGB(s, sQue))
Next
End Sub
End Class
Public Module Module1
Friend WithEvents NewGB As System.Windows.Forms.GroupBox
Friend WithEvents NewCLB As System.Windows.Forms.CheckedListBox
Public NextColumn As Integer = 0
Public Function MakeNewGB(lbl As String, clbItems() As String) As GroupBox
NewGB = New System.Windows.Forms.GroupBox()
NewCLB = New System.Windows.Forms.CheckedListBox()
NewGB.SuspendLayout()
'GroupBox1
'
NewGB.Controls.Add(NewCLB)
NewGB.Location = New System.Drawing.Point(NextColumn, 0)
NewGB.Name = lbl
NewGB.Size = New System.Drawing.Size(126, 210)
NewGB.TabIndex = 0
NewGB.TabStop = False
NewGB.Text = lbl
'
'CheckedListBox1
'
NewCLB.FormattingEnabled = True
NewCLB.Location = New System.Drawing.Point(6, 19)
NewCLB.Name = "clb" + lbl
NewCLB.Size = New System.Drawing.Size(103, 184)
NewCLB.TabIndex = 0
NewCLB.Items.AddRange(clbItems)
NextColumn += NewGB.Size.Width + 10
Return NewGB
End Function
End Module
表單加載後,用戶從每個CLB中選擇一些項目。表格上有一個按鈕。單擊按鈕時,我想將每個CLB中的選定CLB項目保存爲文本文件中的各自GB。
怎麼辦?
如何得到我的答案有何評論? – 5uperdan