This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
Form1.cs
175 lines (149 loc) · 5.6 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using DevExpress.XtraBars.Ribbon;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit;
using DevExpress.Portable.Input;
namespace BookmarksAndHyperlinksSimpleExample
{
public partial class Form1 : RibbonForm
{
HyperlinkOptions hyperlinkOptions;
BookmarkOptions bookmarkOptions;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
richEditControl1.LoadDocument("Hyperlinks.docx");
InsertHyperlink();
InsertBookmark();
#region #HyperlinkOptions
hyperlinkOptions = richEditControl1.Options.Hyperlinks;
hyperlinkOptions.EnableUriCorrection = false;
hyperlinkOptions.ModifierKeys = PortableKeys.Shift;
hyperlinkOptions.ShowToolTip = true;
#endregion #Hyperlinkoptions
#region #BookmarkOptions
bookmarkOptions = richEditControl1.Options.Bookmarks;
bookmarkOptions.ConflictNameResolution = ConflictNameAction.Rename;
bookmarkOptions.Visibility = RichEditBookmarkVisibility.Hidden;
#endregion #BookmarkOptions
}
private void InsertBookmark()
{
#region #InsertBookmark
Document document = richEditControl1.Document;
document.BeginUpdate();
DocumentPosition pos = document.Range.Start;
//Create a bookmark to a given position
document.Bookmarks.Create(document.CreateRange(pos, 1), "Top");
//Insert the hyperlink anchored to the created bookmark:
DocumentRange[] foundRanges = document.FindAll("To the Top", SearchOptions.CaseSensitive);
if (foundRanges.Length > 0)
{
document.Hyperlinks.Create(foundRanges[0]);
document.Hyperlinks[1].Anchor = "Top";
}
document.EndUpdate();
#endregion #InsertBookmark
}
private void InsertHyperlink()
{
#region #InsertHyperlink
Document document = richEditControl1.Document;
//Find the specific text string in a document
DocumentRange[] foundRanges = document.FindAll("DevExpress WinForms Rich Text Editor",
SearchOptions.CaseSensitive);
if (foundRanges.Length > 0)
{
//Create a hyperlink from a found range
document.Hyperlinks.Create(foundRanges[0]);
//Set the URI and the tooltip for the created hyperlink
document.Hyperlinks[0].NavigateUri = "https://www.devexpress.com/Products/NET/Controls/WinForms/Rich_Editor/";
document.Hyperlinks[0].ToolTip = "WinForms Rich Text Editor";
}
#endregion #InsertHyperlink
}
#region #Events
private void checkEdit1_CheckedChanged(object sender, EventArgs e)
{
if (checkEdit1.Checked == false)
{
hyperlinkOptions.ShowToolTip = false;
}
else
{
hyperlinkOptions.ShowToolTip = true;
}
}
private void checkEdit2_CheckedChanged(object sender, EventArgs e)
{
if (checkEdit2.Checked == false)
{
hyperlinkOptions.EnableUriCorrection = false;
}
else
{
hyperlinkOptions.EnableUriCorrection = true;
}
}
private void checkEdit4_ColorChanged(object sender, EventArgs e)
{
bookmarkOptions.Color = checkEdit4.Color;
}
private void checkEdit5_CheckedChanged(object sender, EventArgs e)
{
if (checkEdit5.Checked == true)
{
bookmarkOptions.Visibility = RichEditBookmarkVisibility.Visible;
}
else
{
bookmarkOptions.Visibility = RichEditBookmarkVisibility.Auto;
}
}
private void checkEdit3_CheckedChanged(object sender, EventArgs e)
{
if (checkEdit3.CheckState == CheckState.Checked)
{
checkEdit6.CheckState = CheckState.Unchecked;
checkEdit7.CheckState = CheckState.Unchecked;
hyperlinkOptions.ModifierKeys = PortableKeys.Control;
}
else
hyperlinkOptions.ModifierKeys = PortableKeys.None;
}
private void checkEdit6_CheckedChanged(object sender, EventArgs e)
{
if (checkEdit6.CheckState == CheckState.Checked)
{
checkEdit3.CheckState = CheckState.Unchecked;
checkEdit7.CheckState = CheckState.Unchecked;
hyperlinkOptions.ModifierKeys = PortableKeys.Alt;
}
else
hyperlinkOptions.ModifierKeys = PortableKeys.None;
}
private void checkEdit7_CheckedChanged(object sender, EventArgs e)
{
if (checkEdit7.CheckState == CheckState.Checked)
{
checkEdit6.CheckState = CheckState.Unchecked;
checkEdit3.CheckState = CheckState.Unchecked;
hyperlinkOptions.ModifierKeys = PortableKeys.Shift;
}
else
hyperlinkOptions.ModifierKeys = PortableKeys.None;
}
#endregion #Events
}
}