This repository has been archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
61 lines (55 loc) · 2.35 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
60
61
#Region "#usings"
Imports System
Imports System.Drawing
Imports DevExpress.XtraRichEdit.API.Native
#End Region ' #usings
Namespace WindowsFormsApplication1
Partial Public Class Form1
Inherits DevExpress.XtraBars.Ribbon.RibbonForm
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
richEditControl1.CreateNewDocument()
End Sub
Private Sub barButtonItem1_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles barButtonItem1.ItemClick
' #Region "#FixedRangeUse"
Dim document As Document = richEditControl1.Document
document.AppendText("First text block without formatting. ")
Dim formattedRangeBold = document.AppendText("Second text block with bold font. ").GetFixedRange()
document.AppendText("Third text block without formatting. ")
Dim formattedRangeUnderlined = document.AppendText("Fourth text block with underlined font. ").GetFixedRange()
Dim charsBold = document.BeginUpdateCharacters(formattedRangeBold)
charsBold.Bold = True
document.EndUpdateCharacters(charsBold)
Dim charsUnderline = document.BeginUpdateCharacters(formattedRangeUnderlined)
charsUnderline.Underline = UnderlineType.Single
charsUnderline.UnderlineColor = Color.Brown
document.EndUpdateCharacters(charsUnderline)
' #End Region ' #FixedRangeUse
End Sub
End Class
#Region "#FixedRangeExtension"
Public Module FixedRangeExtension
<System.Runtime.CompilerServices.Extension> _
Public Function GetFixedRange(ByVal range As DocumentRange) As CustomFixedRange
Return New CustomFixedRange(range)
End Function
<System.Runtime.CompilerServices.Extension> _
Public Function BeginUpdateCharacters(ByVal document As Document, ByVal range As CustomFixedRange) As CharacterProperties
Return document.BeginUpdateCharacters(range.CreateRange(document))
End Function
End Module
Public Class CustomFixedRange
Private start As Integer
Private length As Integer
Public Sub New(ByVal range As DocumentRange)
Me.start = range.Start.ToInt()
Me.length = range.Length
End Sub
Public Function CreateRange(ByVal document As Document) As DocumentRange
Return document.CreateRange(start, length)
End Function
End Class
#End Region ' #FixedRangeExtension
End Namespace