WinForm设计之配置文件

Author:水如烟  

代码见应用类代码辅助类代码

 在这是第三次说配置文件,因为有了泛型,所以现在做的也更简单,使用也更方便了。

示例代码:

Public   Class  MainForm

    
Private  gConfigManager  As   New  LzmTW.ConfigManger( Of  Student)

    
Private   Sub  MainForm_Load( ByVal  sender  As   Object ByVal  e  As  System.EventArgs)  Handles   Me .Load
        
Me .PropertyGrid1.SelectedObject  =   Me .gConfigManager
    
End Sub

    
Private   Sub  ReadButton_Click( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  ReadButton.Click
        gConfigManager.Read()
    
End Sub

    
Private   Sub  SaveButton_Click( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  SaveButton.Click
        gConfigManager.Save()
    
End Sub

    
Private   Sub  DataGridButton_Click( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  DataGridButton.Click
        
Dim  table  As  DataTable  =  LzmTW.uSystem.uReflection.DatasFunction.CreateTableFromType( GetType (Student))
        
With  gConfigManager.GetEnumerator
            
While  .MoveNext
                LzmTW.uSystem.uReflection.DatasFunction.ItemAppendToTable(
Of  Student)(.Current, table)
            
End   While
        
End   With
        table.AcceptChanges()
        
Me .DataGridView1.DataSource  =  table
    
End Sub

    
Private   Sub  OutputNameButton_Click( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  OutputNameButton.Click
        
Me .gConfigManager.ForEach( AddressOf  printName)
    
End Sub

    
Private   Sub  printName( ByVal  item  As  Student)
        Console.WriteLine(item.Name)
    
End Sub

    
Private   Sub  FindNameButton_Click( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  FindNameButton.Click
        Console.WriteLine(
Me .gConfigManager.Find( " Name " " 张三 " ).NO)
    
End Sub

End Class

 

< Serializable() >  _
Public   Class  Student
    
Private  gName  As   String
    
Private  gNO  As   String
    
Private  gBirthday  As   Date
    
Public   Property  Name()  As   String
        
Get
            
Return  gName
        
End   Get
        
Set ( ByVal  value  As   String )
            gName 
=  value
        
End   Set
    
End Property

    
Public   Property  NO()  As   String
        
Get
            
Return  gNO
        
End   Get
        
Set ( ByVal  value  As   String )
            gNO 
=  value
        
End   Set
    
End Property

    
Public   Property  Birthday()  As   Date
        
Get
            
Return  gBirthday
        
End   Get
        
Set ( ByVal  value  As   Date )
            gBirthday 
=  value
        
End   Set
    
End Property
End Class

步骤说明:

第一次运行时数据集是空的,所以要在PropertyGrid的Collection项目上添加项目。之后保存文件。

下次运行时,可以读文件了。

效果图解:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值