AN TOAN Khong thé sử dung được phương thức. thuộc tinh chi thuộc lớp cha
Chương 2. MÔ HÌNH MVC VÀ DO ÁN MINH HỌA
2.4.2 Các thành viên dữ liệu
Lớp StyledTextArea có một constructor mà không chấp nhận những đối sé.
Nó gồm có duy nhất của hang mà gọi là phương thức InitializeComponent
Public Sub New()
InitializeComponents() End Sub
Thuộc tính CaretColor
-Mục đích: Đại điện cho mau con nháy trong đổi tượng View.
Public Property CaretColor() As Color Get
Return view.CaretColor
End Get
Set(ByVal caretColor As Color) view.CaretColor = caretColor End Set
End Property
Thuộc tính CaretColumnNo
-Mục đích: Đại diện cho vị trí cột của con nháy. Sử dung thuộc tính nay ở trong View
Friend Property CaretColumnNo() As Integer Get
Return caretLocation.Column End Get
Set(By Val newColumnNo As Integer)
If newColumnNo > 0 And newColumnNo <=
GetCurrentLine().Length + | Then
Dim oldColumnNo As Integer = caretl.ocation.Column caretLocation.Column = newColumnNo
If oldColumnNo < newColumnNo Then OnColumnChanged(New
ColumnkventArgs(oldColumnNo, newColumnNo))
End If
End If
End Set
End Property
76
Thuộc tính CaretLineNo
-Mục đích: Đại diện cho vị trí hàng của con nháy. Sử dụng thuộc tính này ở trong View
Friend Property CaretLineNo() As Integer
Get
Return caretLocation.Line End Get
Set(ByVal newLineNo As Integer)
If newLincNo > 0 And newLincNo <= model.LineCount Then Dim oldLineNo As Integer = caretl.ocation.Line
caretLocation.Line = newLineNo
If oldl.ineNo <> newLineNo Then
OnLineChanged(New LincEventArgs(oldLineNo, newLineNo))
End If End If
End Set
End Property
77
Thuộc tính Edited
-Mục đích: Chi ra có phải một ký tự được chén hay xóa. Chương trình dùng
SIyledTextArea dé hiện thị nội dung của tải liệu có thẻ thiết lập lại thuộc tinh này bắt cứ khi nào tải liệu thiết lập lại.
Public Property Edited() As Boolean Get
Return cditedField End Get
Set(By Val value As Boolean)
‘allows it to be reseUset,
‘for example if the document using this control is saved
editedField = value End Set
End Property
Thuộc tinh HighlightBackColor
-Mục dich: Dai điện cho nén tô mau của van ban được lựa chon:
Public Property HighlightBackColor() As Color Get
Return view. highlightBackColor End Get
Set(By Val color As Color)
view. highlightBackColor = color End Set
End Property
78
Thuộc tỉnh HighlightForeColor
-Mục đích: Đại diện cho màu của văn bản được lựa chọn
Public Property HigphlightForeColor() As Color
Get
Return view. highlightForeColor
End Get
Set(By Val color As Color)
view. highlightForeColor = color End Set
End Property
Thuộc tính LineCount
-Mục đích: Thu được số hàng
Public ReadOnly Property LineCount() As Integer Get
Return model.LineCount End Get
End Property
79
Thuộc tính LineNumberBackColor
-Mục dich: Dai diện cho màu nèn của đối tượng [.ineNumberView
Public Property [.ineNumberBackColor() As Color Get
Return lineNumberView.BackColor End Get
Set(By Val color As Color)
linceNumberView.BackColor = color
End Set
End Property
Thuộc tinh LineNumberForeColor
-Mục dich: Dai diện cho mau được dùng dé vẽ những sé dòng
Public Property LineNumberForeColor() As Color Get
Return lineNumberView.ForeColor End Get
Set(By Val color As Color)
lineNumberView.F oreColor = color End Set
End Property
80
Thuộc tính SelectedText
-Mục đích: Đại điện cho văn bản dược lựa chọn bởi người dùng
Public ReadOnly Property SelectedText() As String
Get
If HasSelection() Then
Dim x1. yl, x2. y2 As Integer
x1 = selectionStartLocation.Column yl = selectionStartLocation.Line
x2 = selectionl:ndLocation.Column y2 = selectionEndLocation.Line
‘swap if necessary
If yl > y2 Or (yl = y2 And x! > x2) Then
Dim t As Integer
t=xl:xl =x2:x2=t t=yl:y! =y2:y2 =t End If
If yt = y2 Then
Return model.Getl.ine(y | ).Substring(xl - 1. x2 - x1) Else
Dim sb As New StringBuilder(model.CharCount + 2 * model.LineCount)
Dim lineCount As Integer = model.LineCount Dim i, lineNo As Integer
For ¡ = yl To y2
Dim thisLine As String = model.GetLine(i)
Ifi= yl Then
sb.Append(thisl.ine.Substring(x! - 1))
Elselfi = y2 Then
sb.Append{ Microsoft. Visual Basic.Constants. vbCr11) sb.Append(thisLine.Substring(0. x2 - 1))
Else
sb.Append( Microsoft. Visual Basic.Constants.vbCr.f)
sb.Append(thisLine) End If
Next
Return sb. ToString() End If
Else
Return ""
End If End Get End Property
Thuộc tính Text
-Mục đích: lại diện cho tất ca Văn bản trong điều khién StyledTextArea. Việc đặt
thuộc tinh này ghi dé lên văn bản trước đây
Public Overrides Property Text() As String
ret
Dim sb As New StringBuilder(model.CharCount + 2 * model.LineCount) Dim lineCount As Integer = model.LineCount
Dim i As Integer
For i= | To lincCount
Dim thisLine As String = mode}.GetLine{i) sb.Append(thisL ine)
If i < lineCount Then
sb.Append( Microsoft. VisualBasic.Constants.vbCrL.f) End If
Next
Return sb. ToString() End Get
Set(By Val s As String)
If Not s Is Nothing Then
Dim initialColumn As Integer = carctLocation.Column Dim initial ine As Integer = caretLocation.Line
‘remove all lines Dim i As Integer
Dim lineCount As Integer = model.L.ineCount
83
For i - 2 To lineCount
model. RemoveLine(2, False)
Next
model. SetLine( 1. ""}' don't remove the first line
caretl ocaton.Column = | caretlocation.Line = |
caret[.ocation = model.InsertData(s. caret] ocation)
If caretl.ocation.Column < initialColumn Then
OnColumnChanged(New _
ColumnE ventArgs(initialColumn, caretlocation.Column))
End If
If caretl.ocation.Line <> initiall.ine Then
Onl.ineChanged(New LineEventAres(initall.ine. caret[ocation.L.ine)) End If
ResetSelection()
If Not view.IsCaretVisible() Then Scroll ToShowCaret()
End If
RedrawAll() End If
End Set
End Property
84
Thuộc tính TextBackColor
-Mục đích: Dai điện cho màu nẻn của đôi tượng View
Public Property TextBackColor() As Color
Get
Return view.BackColor End Get
Set(By Val color As Color)
view.BackColor = color End Set
End Property
Thuộc tính TextForeColor
-Mục đích: Dai diện cho màu được sử dung đẻ vé van ban trong đối tượng
View
Public Property TextForeColor() As Color
Get
Return view.ForeColor End Get
Set(By Val color As Color)
view.ForeColor = color
End Set
End Property
85