-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
59 lines (51 loc) · 2.57 KB
/
Form1.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
55
56
57
58
59
Imports DevExpress.Office.Services
Imports DevExpress.XtraEditors
Imports DevExpress.XtraRichEdit.API.Native
Imports System
Imports System.Net
Namespace Retain_Img_Src
Partial Public Class Form1
Inherits XtraForm
Private imageUri As String = "https://raw.githubusercontent.com/DevExpress-Examples/how-to-retain-original-image-uri-in-html-document-e3189/17.1.3%2B/images/winforms.png"
Public Sub New()
InitializeComponent()
AddHandler richEditControl1.DocumentLoaded, AddressOf richEditControl1_DocumentLoaded
richEditControl1.CreateNewDocument()
Dim pos As DocumentPosition = richEditControl1.Document.CaretPosition
richEditControl1.Document.Images.Insert(pos, DocumentImageSource.FromUri(imageUri, Nothing))
embedImagesCheck.EditValue = True
AddHandler richEditControl1.ContentChanged, AddressOf richEditControl1_ContentChanged
End Sub
Private Sub richEditControl1_ContentChanged(ByVal sender As Object, ByVal e As EventArgs)
ReloadHtml()
End Sub
Private Sub ReloadHtml()
Dim exportOptions As New DevExpress.XtraRichEdit.Export.HtmlDocumentExporterOptions()
exportOptions.EmbedImages = embedImagesCheck.Checked
Dim sText As String = richEditControl1.Document.GetHtmlText(richEditControl1.Document.Range, New CustomUriProvider(), exportOptions)
memoEdit1.Text = sText
End Sub
Private Sub richEditControl1_DocumentLoaded(ByVal sender As Object, ByVal e As EventArgs)
Dim service As IUriProviderService = richEditControl1.GetService(Of IUriProviderService)()
If service IsNot Nothing Then
service.RegisterProvider(New CustomUriProvider())
End If
End Sub
Private Sub embedImagesCheck_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles embedImagesCheck.CheckedChanged
If embedImagesCheck.Checked Then
lblText.Text = "The text is the GetHtml method's result. The image is embedded. The CustomUriProvider is idle."
Else
lblText.Text = "The text is the GetHtml method's result. The image is linked. The CustomUriProvider.CreateImageUri method sets the src."
End If
ReloadHtml()
End Sub
Private Sub btnInsertImage_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim pos As DocumentPosition = richEditControl1.Document.CaretPosition
richEditControl1.Document.Images.Insert(pos, DocumentImageSource.FromUri(imageUri, Nothing))
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
richEditControl1.SaveDocument("test.html", DevExpress.XtraRichEdit.DocumentFormat.Html)
System.Diagnostics.Process.Start("test.html")
End Sub
End Class
End Namespace