我正在使用此代码从文件sQue.txt创建GroupBox读取,并且我正在填充从文件sObj.txt读取的CheckedListBox。加载表单时,将创建多个GB(基于sQue.txt中的条目计数),并在每个GB中包含一个CLB和sObj.txt中的项目。这是工作代码:
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保存。
怎么做?
答案 0 :(得分:0)
•您想要处理按钮点击事件
•使用streamwriter或file.write来记录已经做出的选择
•您希望使用类似下面的内容进行选择
for each gpx as groupbox in me
for each rbx as radiobox in gpx.controls
if control.gettype is gettype(radiobox) then
if rbx.selected = true then
'write to a stringbuilder or something
end if
end if
next
next
再写一些代码,让我们知道你是怎么做的:)