NSDFile.NSDCopyFile メンバ
ファイルを非同期コピーします。
●コンストラクタ
名前 説明 NSDFile.NSDCopyFile NSDFile.NSDCopyFileを初期化します。
●プロパティの一覧
名前 説明 IsCopyFileRunning CopyFileが稼働中かを返します。 SynchronizationCopyFileEnd 同期コピーの終了有無を返します。 SourceFile コピー元のファイルを返します。 DestinationFile コピー先のファイルを返します。 StopCopyFile コピーファイルの中止を設定します。 CopyFile_AsynchronizationSize このファイルサイズを超えると非同期処理を行います。
●メソッドの一覧
名前 引数 戻り値 説明 Dispose なし なし リソースの解放を行います。 GetEndStyleMsg ( NSDFileCopy_EndStyle ) String型 終了スタイルの内容を返します。 CopyFile ( String , String , Boolean , Boolean , FileCopyEventHandler , FileCopyEventHandler , NSD_Asynchronization_DispControl , Object ) Boolean型 ファイルをコピーします。 SetControl_Init ( NSD_Asynchronization_DispControl ) Boolean型 設定コントロールを初期化します。
●イベントの一覧
名前 引数 戻り値 説明 Event_CopyFileDataWrite ( Object, NSDFileCopyEventArgs ) なし コピー先にデータが書き込まれた時に返すイベント。 Event_CopyFileEnd ( Object, NSDFileCopyEventArgs ) なし コピーが終了した時に返すイベント。
●定数の一覧
名前:NSDFileCopy_EndStyle (終了スタイル。) 名前 内容 NoErr エラーなし。 Running 実行中。 ErrStop エラーにより中断。 UserStop ストップが行われた。 NotFreeSpace コピー先に空き容量がありません。 NotSourceFile コピー元ファイルがありません。 NotSourceFolder コピー元フォルダーがありません。
●NSDCopyFileコンストラクタの説明
構文:Public Sub New()
使用法:Dim Cls_CopyFile As New NSDFile.NSDCopyFile
引数:なし。
使用例:
Public Class Form1 Dim Cls_CopyFile As New NSDFile.NSDCopyFile : End Class
●NSDCopyFileプロパティの説明
名前:IsCopyFileRunning
構文:Public ReadOnly Property IsCopyFileRunning() As NSD_File_Run_Style
機能:CopyFileが稼働中かを返します。
Set値:なし。
Get値:稼働中かを返します。(NSD_File_Run_Style)
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' 稼動有無で処理を分けます. Private Sub Button_Copy_OK_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button_Copy_OK.Click Try Select Case Cls_CopyFile.IsCopyFileRunning Case NSDFile.NSD_File_Run_Style.NotRunning ' 稼動していません. Case NSDFile.NSD_File_Run_Style.Running ' 稼働中です. End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
名前:SynchronizationCopyFileEnd
構文:Public Readonly Property SynchronizationCopyFileEnd() As Boolean 機能:同期コピーの終了有無を返します。
Set値:なし。
Get値:True :同期コピーでコピーしました。
False: 非同期コピーでコピーしました。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) Dim Str_Msg As String = Nothing Str_Msg = "コピー元:" & Cls_CopyFile.SourceFile & vbCrLf Str_Msg &= "コピー先:" & Cls_CopyFile.DestinationFile & vbCrLf If Cls_CopyFile.SynchronizationCopyFileEnd Then Str_Msg &= "同期コピーされました。" Else Str_Msg &= "非同期コピーされました。" End If MsgBox(Str_Msg) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
名前:SourceFile
構文:Public ReadOnly Property SourceFile() As String 機能:コピー元のファイルを返します。
Set値:なし。
Get値:コピー元のファイル。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) Dim Str_Msg As String = Nothing Str_Msg = "コピー元:" & Cls_CopyFile.SourceFile & vbCrLf Str_Msg &= "コピー先:" & Cls_CopyFile.DestinationFile & vbCrLf If Cls_CopyFile.SynchronizationCopyFileEnd Then Str_Msg &= "同期コピーされました。" Else Str_Msg &= "非同期コピーされました。" End If MsgBox(Str_Msg) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
名前:DestinationFile
構文:Public ReadOnly Property DestinationFile() As String 機能:コピー先のファイルを返します。
Set値:なし。
Get値:コピー先のファイル。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) Dim Str_Msg As String = Nothing Str_Msg = "コピー元:" & Cls_CopyFile.SourceFile & vbCrLf Str_Msg &= "コピー先:" & Cls_CopyFile.DestinationFile & vbCrLf If Cls_CopyFile.SynchronizationCopyFileEnd Then Str_Msg &= "同期コピーされました。" Else Str_Msg &= "非同期コピーされました。" End If MsgBox(Str_Msg) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
名前:StopCopyFile
構文:Public Property StopCopyFile() As Boolean 機能:コピーファイルの中止を設定します。
Set値:True :コピーを中止します。
False:コピーを中止しません。
Get値:Set値を参照。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
名前:CopyFile_AsynchronizationSize
構文:Public Property CopyFile_AsynchronizationSize() As Long 機能:このファイルサイズを超えると非同期処理を行います。
Set値:非同期処理を行うサイズを指定します。
Get値:Set値を参照。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If ' 非同期処理を行うサイズを指定します. Cls_CopyFile.CopyFile_AsynchronizationSize = 65536 Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
●NSDCopyFileメソッド の説明
名前:Dispose
構文:Public Overridable Sub Dispose() Implements IDisposable.Dispose 機能:リソースの解放を行います。
※終了時に必ず呼び出します。
引数:なし。
戻り値:なし。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub End Class
名前:GetEndStyleMsg
構文:Public Function GetEndStyleMsg( EndStyle ) As String
機能:終了スタイルの内容を返します。
引数:
名前 型 引数渡しの方法 説明 EndStyle NSDFileCopy_EndStyle 値渡し(ByVal) 終了スタイルを渡します。 戻り値:String
戻り値の説明:
終了スタイルの内容を返します。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
名前:CopyFile
構文:Public Function CopyFile( SourceFile , DestinationFile , OverWrite , OverWriteReadOnly , Event_CopyFileDataWrite , Event_CopyFileEnd , Control , Object ) As Boolean 機能:ファイルをコピーします。
引数:
名前 型 引数渡しの方法 説明 SourceFile String 値渡し(ByVal) コピー元ファイルのフルパス名を渡します。 DestinationFile String 値渡し(ByVal) コピー先のフルパス名を渡します。 OverWrite Boolean 値渡し(ByVal) 上書き指定を渡します。
True :上書きを行います。
False:上書きは行いません。OverWriteReadOnly Boolean 値渡し(ByVal) 読込専用属性の場合の上書き指定を渡します。
True :上書きを行います。
False:上書きは行いません。Event_CopyFileDataWrite FileCopyEventHandler 値渡し(ByVal) コピー先にデータが書き込まれた時に呼び出すイベント関数のアドレスを渡します。
※イベント関数が不要な場合は、Nothingを渡します。Event_CopyFileEnd FileCopyEventHandler 値渡し(ByVal) コピーが終了した時に呼び出すイベント関数のアドレスを渡します。
※イベント関数が不要な場合は、Nothingを渡します。Control NSD_Asynchronization_DispControl 値渡し(ByVal) コピーファイル中で値を変更するコントロール情報を渡します。
※コントロール情報を指定しない場合は、Nothingを渡します。Object Object 値渡し(ByVal) イベント関数に返すオブジェクトを渡します。
※オブジェクトを指定しない場合は、Nothingを渡します。戻り値:Boolean
戻り値の説明:
True:成功 False:失敗
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' コピーファイル用の表示コントロール. Dim Cls_CopyFileDispControl As New NSDFile.NSD_Asynchronization_DispControl ' Loadイベント. Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs _ ) Handles Me.Load Try ' プログレスバーをセット. Cls_CopyFileDispControl.AddProgressBar(Me.PB_Copy) ' コピーサイズ表示用ラベルをセット. Cls_CopyFileDispControl.AddControl(Me.Label_CopySize, _ NSDFile.NSD_DispControl_Style.ChangeText, _ NSDFile.NSD_DispControl_TextStyle.CopyFile_SourceSizeAndCopySize + _ NSDFile.NSD_DispControl_TextStyle.Plus_Kanma + _ NSDFile.NSD_DispControl_TextStyle.Plus_UnitChange, _ "1ファイルのコピー状況", _ " [", _ "]") ' コピー状況のパーセント表示用ラベルをセット. Cls_CopyFileDispControl.AddControl(Me.Label_Parsent, _ NSDFile.NSD_DispControl_Style.ChangeText, _ NSDFile.NSD_DispControl_TextStyle.CopyFile_Parsent, _ "", _ "(", _ "%)") Catch ex As Exception End Try End Sub ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイル用コントロールの解放処理. If Not (Cls_CopyFileDispControl Is Nothing) Then Cls_CopyFileDispControl.Dispose() Cls_CopyFileDispControl= Nothing End If ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Cls_CopyFileDispControl, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' 稼動有無で処理を分けます. Private Sub Button_Copy_OK_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button_Copy_OK.Click Try Select Case Cls_CopyFile.IsCopyFileRunning Case NSDFile.NSD_File_Run_Style.NotRunning ' 稼動していません. Case NSDFile.NSD_File_Run_Style.Running ' 稼働中です. End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try If e.SourceFileSize > 1000000 Then ' コピー元のファイルサイズが1000000バイトを超える場合は、コピーを中止します. e.SearchStop = True Else Dim Lng_SourceSize As Long = e.SourceFileSize ' コピー元のファイルサイズ. Dim Lng_CopySize As Long = e.CopySize ' コピーしたサイズ. : End If Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try If Me.InvokeRequired Then Me.Invoke(New SetName_Invoke(AddressOf SetButton_CopyFile), New Object() {"コピー"} ) Else Me.SetButton_CopyFile("コピー") End If MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) Dim Str_Msg As String = Nothing Str_Msg = "コピー元:" & Cls_CopyFile.SourceFile & vbCrLf Str_Msg &= "コピー先:" & Cls_CopyFile.DestinationFile & vbCrLf If Cls_CopyFile.SynchronizationCopyFileEnd Then Str_Msg &= "同期コピーされました。" Else Str_Msg &= "非同期コピーされました。" End If MsgBox(Str_Msg) ' コントロールを初期化します. Cls_CopyFile.SetControl_Init(Cls_CopyFileDispControl) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub ' コピー用ボタンのテキスト設定. Public Sub SetButton_CopyFile(ByVal StrVal_Text As String) Try Me.Button_Copy.Text = StrVal_Text Catch ex As Exception End Try End Sub End Class
名前:SetControl_Init
構文:Public Function SetControl_Init( Control ) As Boolean 機能:設定コントロールを初期化します。
引数:
名前 型 引数渡しの方法 説明 Control NSD_Asynchronization_DispControl 値渡し(ByVal) コントロールの情報を渡します。 戻り値:Boolean
戻り値の説明:
True:成功 False:失敗
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' コピーファイル用の表示コントロール. Dim Cls_CopyFileDispControl As New NSDFile.NSD_Asynchronization_DispControl ' Loadイベント. Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs _ ) Handles Me.Load Try ' プログレスバーをセット. Cls_CopyFileDispControl.AddProgressBar(Me.PB_Copy) ' コピーサイズ表示用ラベルをセット. Cls_CopyFileDispControl.AddControl(Me.Label_CopySize, _ NSDFile.NSD_DispControl_Style.ChangeText, _ NSDFile.NSD_DispControl_TextStyle.CopyFile_SourceSizeAndCopySize + _ NSDFile.NSD_DispControl_TextStyle.Plus_Kanma + _ NSDFile.NSD_DispControl_TextStyle.Plus_UnitChange, _ "1ファイルのコピー状況", _ " [", _ "]") ' コピー状況のパーセント表示用ラベルをセット. Cls_CopyFileDispControl.AddControl(Me.Label_Parsent, _ NSDFile.NSD_DispControl_Style.ChangeText, _ NSDFile.NSD_DispControl_TextStyle.CopyFile_Parsent, _ "", _ "(", _ "%)") Catch ex As Exception End Try End Sub ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイル用コントロールの解放処理. If Not (Cls_CopyFileDispControl Is Nothing) Then Cls_CopyFileDispControl.Dispose() Cls_CopyFileDispControl= Nothing End If ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If ' 非同期処理を行うサイズを指定します. Cls_CopyFile.CopyFile_AsynchronizationSize = 65536 Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Cls_CopyFileDispControl, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' 稼動有無で処理を分けます. Private Sub Button_Copy_OK_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button_Copy_OK.Click Try Select Case Cls_CopyFile.IsCopyFileRunning Case NSDFile.NSD_File_Run_Style.NotRunning ' 稼動していません. Case NSDFile.NSD_File_Run_Style.Running ' 稼働中です. End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try If e.SourceFileSize > 1000000 Then ' コピー元のファイルサイズが1000000バイトを超える場合は、コピーを中止します. e.SearchStop = True Else Dim Lng_SourceSize As Long = e.SourceFileSize ' コピー元のファイルサイズ. Dim Lng_CopySize As Long = e.CopySize ' コピーしたサイズ. : End If Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try If Me.InvokeRequired Then Me.Invoke(New SetName_Invoke(AddressOf SetButton_CopyFile), New Object() {"コピー"} ) Else Me.SetButton_CopyFile("コピー") End If MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) Dim Str_Msg As String = Nothing Str_Msg = "コピー元:" & Cls_CopyFile.SourceFile & vbCrLf Str_Msg &= "コピー先:" & Cls_CopyFile.DestinationFile & vbCrLf If Cls_CopyFile.SynchronizationCopyFileEnd Then Str_Msg &= "同期コピーされました。" Else Str_Msg &= "非同期コピーされました。" End If MsgBox(Str_Msg) ' コントロールを初期化します. Cls_CopyFile.SetControl_Init(Cls_CopyFileDispControl) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub ' コピー用ボタンのテキスト設定. Public Sub SetButton_CopyFile(ByVal StrVal_Text As String) Try Me.Button_Copy.Text = StrVal_Text Catch ex As Exception End Try End Sub End Class
●NSDCopyFileイベントの説明
名前:Event_CopyFileDataWrite
構文:Public Sub Event_CopyFileDataWrite( sender , e )
機能:コピー先にデータが書き込まれた時に発生するイベント。
※CopyFileの第5引数でアドレスを渡します。
引数:
名前 型 引数渡しの方法 説明 sender Object 値渡し(ByVal) Nothingが渡されます。 e NSDFileCopyEventArgs 値渡し(ByVal) ファイルコピー用のイベントが渡されます。 戻り値:なし。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try If e.SourceFileSize > 1000000 Then ' コピー元のファイルサイズが1000000バイトを超える場合は、コピーを中止します. e.SearchStop = True Else Dim Lng_SourceSize As Long = e.SourceFileSize ' コピー元のファイルサイズ. Dim Lng_CopySize As Long = e.CopySize ' コピーしたサイズ. : End If Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
名前:Event_CopyFileEnd
構文:Public Sub Event_CopyFileEnd( sender , e )
機能:コピーが終了した時に発生するイベント。
※CopyFileの第6引数でアドレスを渡します。
引数:
名前 型 引数渡しの方法 説明 sender Object 値渡し(ByVal) Nothingが渡されます。 e NSDFileCopyEventArgs 値渡し(ByVal) ファイルコピー用のイベントが渡されます。 戻り値:なし。
使用例:
Public Class Form1 ' ファイルコピー用. Dim Cls_CopyFile As NSDFile.NSDCopyFile = Nothing ' ファイルのコピーフラグ True:コピー中 False:コピーしていません. Dim BlnCls_CopyFileFolder As Boolean = False ' FormClosing. Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs _ ) Handles Me.FormClosing Try ' コピーファイルの解放. If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End If Catch ex As Exception End Try End Sub ' コピー. Private Sub Button_Copy_Click( ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button_Copy.Click Try Select Case BlnCls_CopyFileFolder Case False ' コピーを行います. Dim Str_Source As String = Me.TextBoxSource.Text Dim Str_Destination As String = Me.TextBoxDestination.Text Me.Button_Copy.Text = "中止" BlnCls_CopyFileFolder = True ' ファイルのコピー. If (Cls_CopyFile Is Nothing) Then Cls_CopyFile = New NSDFile.NSDCopyFile End If Cls_CopyFile.CopyFile(Str_Source, _ Str_Destination, _ True, _ True, _ AddressOf Event_CopyFileDataWriteCallback, _ AddressOf Event_CopyFileEndCallback, _ Nothing, _ Nothing) Case Else ' コピーを中止します. Me.Button_Copy.Text = "コピー" If Not (Cls_CopyFile Is Nothing) Then Cls_CopyFile.StopCopyFile = True End If BlnCls_CopyFileFolder = False End Select Catch ex As Exception End Try End Sub ' コピー先にデータが書き込まれた時に呼び出されるイベント関数. Public Sub Event_CopyFileDataWriteCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try : Catch ex As Exception End Try End Sub ' コピー終了時に呼び出されるイベント関数. Public Sub Event_CopyFileEndCallback(ByVal sender As Object, _ ByVal e As NSDFile.NSDCopyFile.NSDFileCopyEventArgs) Try MsgBox(Cls_CopyFile.GetEndStyleMsg(e.EndStyle)) BlnCls_CopyFileFolder = False Catch ex As Exception Finally Cls_CopyFile.Dispose() Cls_CopyFile = Nothing End Try End Sub End Class
Copyright (C) 2010-2012 Nihon System Developer Corp. All Rights Reserved.