Сохранение файла
| Код | Public Sub SaveFile() 'логика получения пути 'формирование параметров для процедуры сохранения 'вызов процедуры сохранения 'отражение результаа сохранения Dim f As frmMain1 f = CType(Me, Form).ParentForm
FolderPath = GetFolderPath() With Me.SaveFileDialog1 .InitialDirectory = FolderPath .Title = "Select a File" .Filter = "RTF Files|*.rtf" End With If strChange = True Then Try If FileName <> Me.Text Then SaveFileDialog1.FileName = Me.Text If SaveFileDialog1.ShowDialog = DialogResult.OK Then FolderPath = SaveFileDialog1.FileName 'MsgBox(FolderPath) 'для тестирования Call FileSaveParameter(rtbText, FolderPath) Call setPathFile() End If Else Call FileSaveParameter(rtbText, FolderPath) End If Catch ex As Exception MessageBox.Show("Ошибка" & ex.ToString) 'If ex.ToString = Nothing Then
'End If End Try Else SaveFileDialog1.FileName = Me.Text If SaveFileDialog1.ShowDialog = DialogResult.OK Then
FolderPath = SaveFileDialog1.FileName 'MsgBox(FolderPath) 'для тестирования Call FileSaveParameter(rtbText, FolderPath) Call setPathFile() End If
End If strChange = False
End Sub
|
Открытия файла
| Код | ''' <summary> ''' Открывает файл из указаного диска ''' </summary> ''' <remarks></remarks> Private Sub FileOpen() Dim activeChild As frmChild = Me.ActiveMdiChild OpenFileDialog1.InitialDirectory = "C:\" OpenFileDialog1.Title = "Select a File" OpenFileDialog1.Filter = "RTF Files|*.rtf" If (Not activeChild Is Nothing) Then Try Dim theBox As RichTextBox = _ CType(activeChild.ActiveControl, RichTextBox) If (Not theBox Is Nothing) Then OpenFileDialog1.FileName = activeChild.Text If OpenFileDialog1.ShowDialog = DialogResult.OK Then 'theBox.Text = System.IO.File.ReadAllText(OpenFileDialog1.FileName) theBox.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText) End If activeChild.Text = OpenFileDialog1.SafeFileName End If Catch ex As Exception MessageBox.Show("Ошибка" & ex.ToString) End Try Else If OpenFileDialog1.ShowDialog = DialogResult.OK Then Call FileOpenFirst() End If End If End Sub
|
Если хочешь скинь mail я тебе сброшу пример легкого редактора |