2013-05-30 63 views
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。

怎麼辦?

+0

如何得到我的答案有何評論? – 5uperdan

回答

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 

去寫更多的代碼,讓我們知道您的:)