0

我正在使用此代码创建从文件 sQue.txt 读取的 GroupBox,并且正在填充从文件 sObj.txt 读取的 CheckedListBox。加载表单时,会创建多个 GB(基于 sQue.txt 中的条目数),并且在每个 GB 中包含一个带有 sObj.txt 中的项目的 CLB。这是工作代码:

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 保存在文本文件中。

怎么做到呢?

4

1 回答 1

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

去写一些更多的代码,让我们知道你的进展:)

于 2013-05-30T12:53:30.147 回答