-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
63 lines (56 loc) · 2.72 KB
/
Form1.cs
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
60
61
62
63
using DevExpress.Office.Services;
using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Net;
namespace Retain_Img_Src
{
public partial class Form1 : XtraForm
{
string imageUri = @"https://raw.githubusercontent.com/DevExpress-Examples/how-to-retain-original-image-uri-in-html-document-e3189/17.1.3%2B/images/winforms.png";
public Form1()
{
InitializeComponent();
richEditControl1.DocumentLoaded += richEditControl1_DocumentLoaded;
richEditControl1.CreateNewDocument();
DocumentPosition pos = richEditControl1.Document.CaretPosition;
richEditControl1.Document.Images.Insert(pos, DocumentImageSource.FromUri(imageUri, null));
embedImagesCheck.EditValue = true;
richEditControl1.ContentChanged += new EventHandler(richEditControl1_ContentChanged);
}
private void richEditControl1_ContentChanged(object sender, EventArgs e) {
ReloadHtml();
}
private void ReloadHtml() {
DevExpress.XtraRichEdit.Export.HtmlDocumentExporterOptions exportOptions = new DevExpress.XtraRichEdit.Export.HtmlDocumentExporterOptions();
exportOptions.EmbedImages = embedImagesCheck.Checked;
string sText = richEditControl1.Document.GetHtmlText(richEditControl1.Document.Range, new CustomUriProvider(), exportOptions);
memoEdit1.Text = sText;
}
private void richEditControl1_DocumentLoaded(object sender, EventArgs e)
{
IUriProviderService service = richEditControl1.GetService<IUriProviderService>();
if (service != null)
{
service.RegisterProvider(new CustomUriProvider());
}
}
private void embedImagesCheck_CheckedChanged(object sender, EventArgs e) {
if (embedImagesCheck.Checked)
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.";
ReloadHtml();
}
private void btnInsertImage_Click(object sender, EventArgs e)
{
DocumentPosition pos = richEditControl1.Document.CaretPosition;
richEditControl1.Document.Images.Insert(pos, DocumentImageSource.FromUri(imageUri, null));
}
private void btnSave_Click(object sender, EventArgs e)
{
richEditControl1.SaveDocument("test.html", DevExpress.XtraRichEdit.DocumentFormat.Html);
System.Diagnostics.Process.Start("test.html");
}
}
}