-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomCommand.vb
54 lines (45 loc) · 2.14 KB
/
CustomCommand.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Imports DevExpress.XtraRichEdit.Services
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.Commands
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Namespace SaveDocumentSample
'#Region "#savecommand"
Public Class CustomRichEditCommandFactoryService
Implements IRichEditCommandFactoryService
Private ReadOnly service As IRichEditCommandFactoryService
Private ReadOnly control As RichEditControl
Public Sub New(ByVal control As RichEditControl, ByVal service As IRichEditCommandFactoryService)
DevExpress.Utils.Guard.ArgumentNotNull(control, "control")
DevExpress.Utils.Guard.ArgumentNotNull(service, "service")
Me.control = control
Me.service = service
End Sub
Public Function CreateCommand(ByVal id As RichEditCommandId) As RichEditCommand Implements IRichEditCommandFactoryService.CreateCommand
If id = RichEditCommandId.FileSaveAs Then Return New CustomSaveDocumentAsCommand(control)
Return service.CreateCommand(id)
End Function
End Class
Public Class CustomSaveDocumentAsCommand
Inherits SaveDocumentAsCommand
Public Sub New(ByVal control As IRichEditControl)
MyBase.New(control)
End Sub
Protected Overrides Sub ExecuteCore()
Using dialog As XtraSaveFileDialog = New XtraSaveFileDialog With {
.Filter = "Rich Text Format Files (*.rtf)|*.rtf|All Files (*.*)|*.*",
.FileName = "SavedDocument.rtf", .RestoreDirectory = True,
.CheckFileExists = False, .CheckPathExists = True,
.OverwritePrompt = True, .DereferenceLinks = True,
.ValidateNames = True, .AddExtension = False,
.FilterIndex = 1}
dialog.InitialDirectory = "C:\Temp"
If dialog.ShowDialog() = DialogResult.OK Then
CType(Control, RichEditControl).SaveDocument(dialog.FileName, DocumentFormat.Rtf)
End If
End Using
'base.ExecuteCore();
End Sub
End Class
'#End Region ' #savecommand
End Namespace