Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
GN WebStudio - EditorTesto.vb

EditorTesto.vb

Caricato da: GN
Scarica il programma completo

  1. Public Class EditorTesto
  2.     Inherits RichTextBox
  3.     Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
  4.     Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWnd As Integer) As Integer
  5.     Private _Highlighting As Boolean = True
  6.     Public Property Highlighting() As Boolean
  7.         Get
  8.             Return _Highlighting
  9.         End Get
  10.         Set(ByVal value As Boolean)
  11.             _Highlighting = value
  12.             If value = True Then
  13.                 Me.ColoraTutto()
  14.             Else
  15.                 Me.ForeColor = Color.Black
  16.                 LockWindowUpdate(Me.Handle.ToInt32)
  17.                 Me.Select(0, Me.Text.Length)
  18.                 Me.SelectionColor = Color.Black
  19.                 Me.DeselectAll()
  20.                 LockWindowUpdate(0)
  21.             End If
  22.         End Set
  23.     End Property
  24.     Private Sub Me_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
  25.         If e.Control = True And e.KeyCode = Keys.V Then
  26.             e.SuppressKeyPress = False
  27.             Try
  28.                 Me.Incolla()
  29.             Catch ex As Exception
  30.             End Try
  31.         Else
  32.             If Highlighting = True Then
  33.                 LockWindowUpdate(Me.Handle.ToInt32)
  34.                 Me.ColoraRiga(Me.GetLineFromCharIndex(Me.SelectionStart))
  35.                 LockWindowUpdate(0)
  36.             End If
  37.         End If
  38.     End Sub
  39.  
  40.     Sub ColoraTutto()
  41.         LockWindowUpdate(Me.Handle.ToInt32)
  42.         For Indice As Integer = 0 To Me.Lines.Length
  43.             Me.ColoraRiga(Indice)
  44.         Next
  45.         LockWindowUpdate(0)
  46.     End Sub
  47.  
  48.     Sub ColoraRiga(ByVal Riga As Integer)
  49.         Try
  50.             If Me.Lines(Riga).Length = 0 Then
  51.                 Exit Sub
  52.             End If
  53.         Catch ex As Exception
  54.             Exit Sub
  55.         End Try
  56.         Dim posCursore As Integer = Me.SelectionStart
  57.         Dim TagAperto As Boolean = False
  58.         Dim ColoreCorr As Color
  59.         Dim prossimoColore As Color = Nothing
  60.         Dim SeProssimoColore As Boolean = False
  61.         For Indice As Integer = 0 To Me.Lines(Riga).Length - 1
  62.             If Me.Lines(Riga).Chars(Indice) = "<" Then
  63.                 SeProssimoColore = False
  64.                 ColoreCorr = My.Settings.EditorTestoColoreTags
  65.                 TagAperto = True
  66.             ElseIf Me.Lines(Riga).Chars(Indice) = " " Then
  67.                 SeProssimoColore = False
  68.                 If TagAperto = True Then
  69.                     ColoreCorr = My.Settings.EditorTestoColoreAttributi
  70.                 End If
  71.             ElseIf Me.Lines(Riga).Chars(Indice) = "=" Then
  72.                 SeProssimoColore = False
  73.                 If TagAperto = True Then
  74.                     ColoreCorr = My.Settings.EditorTestoColoreValori
  75.                 End If
  76.             ElseIf Me.Lines(Riga).Chars(Indice) = "[" Then
  77.                 SeProssimoColore = False
  78.                 If TagAperto = True Then
  79.                     ColoreCorr = My.Settings.EditorTestoColoreQuadre
  80.                 End If
  81.             ElseIf Me.Lines(Riga).Chars(Indice) = "]" Then
  82.                 SeProssimoColore = False
  83.                 If TagAperto = True Then
  84.                     ColoreCorr = My.Settings.EditorTestoColoreQuadre
  85.                     prossimoColore = My.Settings.EditorTestoColoreTags
  86.                     SeProssimoColore = True
  87.                 End If
  88.             ElseIf Me.Lines(Riga).Chars(Indice) = "]" Then
  89.                 ColoreCorr = My.Settings.EditorTestoColoreQuadre
  90.                 prossimoColore = Color.Black
  91.                 SeProssimoColore = True
  92.             ElseIf Me.Lines(Riga).Chars(Indice) = "-" Then
  93.                 Try
  94.                     If Me.Lines(Riga).Substring(Indice - 2).StartsWith("<!--") Then
  95.                         TagAperto = False
  96.                         ColoreCorr = My.Settings.EditortestoColoreCommenti
  97.                     End If
  98.                 Catch ex As Exception
  99.                 End Try
  100.             ElseIf Me.Lines(Riga).Chars(Indice) = ">" Then
  101.                 ColoreCorr = My.Settings.EditorTestoColoreTags
  102.                 prossimoColore = Color.Black
  103.                 SeProssimoColore = True
  104.                 TagAperto = False
  105.             ElseIf SeProssimoColore = True Then
  106.                 ColoreCorr = prossimoColore
  107.                 SeProssimoColore = False
  108.             End If
  109.             Me.Select(Me.GetFirstCharIndexFromLine(Riga) + Indice, 1)
  110.             Me.SelectionColor = ColoreCorr
  111.             Me.DeselectAll()
  112.         Next
  113.         Me.SelectionStart = posCursore
  114.     End Sub
  115.  
  116.     Sub Incolla()
  117.         If Me.SelectionLength <> 0 Then
  118.             Me.Text.Remove(Me.SelectionStart, Me.SelectionLength)
  119.         End If
  120.         Me.Text.Insert(Me.SelectionStart, My.Computer.Clipboard.GetText)
  121.         If Highlighting = True Then
  122.             Me.ColoraTutto()
  123.         End If
  124.     End Sub
  125. End Class