Imports System Imports System.IO Imports System.Runtime.Serialization Imports System.Runtime.Serialization.Formatters.Binary <Serializable()> Public Class HistoryList Private _Items As New List(Of History) Public Property day As Date = Today Public Sub New() End Sub Public Property Items As List(Of History) Get Return _Items End Get Set(value As List(Of History)) _Items = value End Set End Property Public Sub WriteFile() Dim bf As New BinaryFormatter Using fs As New FileStream(CreatePath(day), FileMode.Create) bf.Serialize(fs, Me) End Using End Sub '読み込み Public Shared Function ReadFile(ByVal readdate As Date) As HistoryList Dim Result As HistoryList Dim bf As New BinaryFormatter If Not My.Computer.FileSystem.FileExists(CreatePath(readdate)) Then Return Nothing End If Using fs As New FileStream(CreatePath(readdate), FileMode.Open) Result = bf.Deserialize(fs) End Using Return Result End Function 'ファイル名生成 Public Shared Function CreateFileName(ByVal filedate As Date) Return filedate.ToString("yyyy-MM-dd") & ".bin" End Function '保存先作成 Public Shared Function CreatePath(ByVal filedate As Date) Return Application.StartupPath & "\" & CreateFileName(filedate) End Function 'TreeNodeに全項目追加 Public Sub TreeViewColumnsAdd(ByVal Parent As TreeNode) For Each index In Items Parent.Nodes.Add(New HistoryTreeViewNode() With {.History = index, .Text = index.Title}) Next End Sub 'TreeNodeに項目を追加するとともに、自分のクラスにも追加 Public Sub TreeViewHistoryListColumnAdd(ByVal Parent As TreeNode, ByVal History As History) If Me.Items.Last.URL = History.URL Then Return End If Parent.Nodes.Add(New HistoryTreeViewNode() With {.History = History, .Text = History.Title}) Me.Items.Add(History) End Sub End Class