设计WinForm的步骤

设计WinForm的步骤

Author:水如烟

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

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

示例代码:

PublicClassMainForm

PrivategConfigManagerAsNewLzmTW.ConfigManger(OfStudent)

PrivateSubMainForm_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.Load
Me.PropertyGrid1.SelectedObject=Me.gConfigManager
EndSub

PrivateSubReadButton_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesReadButton.Click
gConfigManager.Read()

EndSub

PrivateSubSaveButton_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesSaveButton.Click
gConfigManager.Save()

EndSub

PrivateSubDataGridButton_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesDataGridButton.Click
DimtableAsDataTable=LzmTW.uSystem.uReflection.DatasFunction.CreateTableFromType(GetType(Student))
WithgConfigManager.GetEnumerator
While.MoveNext
LzmTW.uSystem.uReflection.DatasFunction.ItemAppendToTable(
OfStudent)(.Current,table)
EndWhile
EndWith
table.AcceptChanges()
Me.DataGridView1.DataSource=table
EndSub

PrivateSubOutputNameButton_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesOutputNameButton.Click
Me.gConfigManager.ForEach(AddressOfprintName)
EndSub

PrivateSubprintName(ByValitemAsStudent)
Console.WriteLine(item.Name)

EndSub

PrivateSubFindNameButton_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesFindNameButton.Click
Console.WriteLine(
Me.gConfigManager.Find("Name","张三").NO)
EndSub

EndClass
<Serializable()>_
PublicClassStudent
PrivategNameAsString
PrivategNOAsString
PrivategBirthdayAsDate
PublicPropertyName()AsString
Get
ReturngName
EndGet
Set(ByValvalueAsString)
gName
=value
EndSet
EndProperty

PublicPropertyNO()AsString
Get
ReturngNO
EndGet
Set(ByValvalueAsString)
gNO
=value
EndSet
EndProperty

PublicPropertyBirthday()AsDate
Get
ReturngBirthday
EndGet
Set(ByValvalueAsDate)
gBirthday
=value
EndSet
EndProperty
EndClass

步骤说明:

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

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

效果图解:

设计WinForm的步骤

设计WinForm的步骤

设计WinForm的步骤

设计WinForm的步骤