elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Ayuda, buscar y resaltar la palabras de un RichTextBox
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda, buscar y resaltar la palabras de un RichTextBox  (Leído 6,926 veces)
**Aincrad**


Desconectado Desconectado

Mensajes: 668



Ver Perfil WWW
Ayuda, buscar y resaltar la palabras de un RichTextBox
« en: 26 Noviembre 2017, 20:30 pm »

bueno como dice el titulo quiero buscar y resaltar una palabra de un RichTextBox1.


este método solo marca la 1era palabra encontrada. y las otras palabras que son las mismas no la subraya.

ejemplo le digo que busque todas las palabras hola , pero solo me marca la primera encontrada y las demás no mas marca.


Código
  1. Dim Search, Where
  2.  
  3.        Search = TextBox1.Text
  4.        Where = InStr(RichTextBox1.Text, Search)
  5.        Dim n As Integer
  6.        If Where Then
  7.            Name = n + 1
  8.            RichTextBox1.Focus()
  9.            RichTextBox1.SelectionStart = Where - 1
  10.            RichTextBox1.SelectionLength = Len(Search)
  11.        Else
  12.            MsgBox("String not found.")
  13.        End If

Gracias de antemano.


En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #1 en: 27 Noviembre 2017, 16:49 pm »

Basicamente a tu código le falta usar la función RichTextBox.Find() junto a un búcle para ir iterando las posiciones de las ocurrencias encontradas en el texto. Lo que has intentado hacer recurriendo al uso de funciones de VB6 como InStr... ese no es el camino en .NET, debes evitar toda esa morralla (basura) de miembros de VB6, ya que son miembros que están ahí solo por compatibilidad, aunque estén escritos en código .NET son miembros cuyo código fuente es muy poco óptimo y limitado, todo esto ya te lo comenté en el pasado pero sigues sin hacer caso del consejo. :-/

Una solucoón que considero sencilla de aplicar para cualquier nivel de aprendizaje, podría ser la siguiente, a modo de función de uso genérico reutilizable para cualquier tipo de ocasión...

Código
  1. ''' ----------------------------------------------------------------------------------------------------
  2. ''' <summary>
  3. ''' Find all the occurrences of the specified strings in the source <see cref="RichTextBox"/>
  4. ''' and set the foreground color, background color, and the font of any occurrence found.
  5. ''' </summary>
  6. ''' ----------------------------------------------------------------------------------------------------
  7. ''' <param name="rtb">
  8. ''' The source <see cref="RichTextBox"/>.
  9. ''' </param>
  10. '''
  11. ''' <param name="find">
  12. ''' An Array containing the strings to match.
  13. ''' </param>
  14. '''
  15. ''' <param name="ignoreCase">
  16. ''' Specifies how a text search is carried out.
  17. ''' </param>
  18. '''
  19. ''' <param name="foreColor">
  20. ''' The foreground color to set for the matched strings.
  21. ''' </param>
  22. '''
  23. ''' <param name="backColor">
  24. ''' The background color to set for the matched strings.
  25. ''' </param>
  26. '''
  27. ''' <param name="font">
  28. ''' The font to set for the matched strings.
  29. ''' </param>
  30. ''' ----------------------------------------------------------------------------------------------------
  31. ''' <returns>
  32. ''' Returns the total amount of occurrences found.
  33. ''' </returns>
  34. ''' ----------------------------------------------------------------------------------------------------
  35. <DebuggerStepThrough>
  36. Public Shared Function InternalColorizeMatches(ByVal rtb As RichTextBox,
  37.                                               ByVal find As String,
  38.                                               ByVal ignoreCase As Boolean,
  39.                                               ByVal foreColor As Color,
  40.                                               ByVal backColor As Color,
  41.                                               ByVal font As Font) As Integer
  42.  
  43.    If String.IsNullOrEmpty(find) Then
  44.        Return 0
  45.    End If
  46.  
  47.    ' Set letter-case criteria.
  48.    Dim richTextBoxFinds As RichTextBoxFinds =
  49.        If(ignoreCase, RichTextBoxFinds.None, RichTextBoxFinds.MatchCase)
  50.    Dim stringComparison As StringComparison =
  51.        If(ignoreCase, StringComparison.OrdinalIgnoreCase, StringComparison.Ordinal)
  52.  
  53.    ' Save the current caret position to restore it at the end.
  54.    Dim caretPosition As Integer = rtb.SelectionStart
  55.  
  56.    Dim successCount As Integer = 0
  57.    Dim textLength As Integer = rtb.TextLength
  58.    Dim firstIndex As Integer = 0
  59.    Dim lastIndex As Integer = rtb.Text.LastIndexOf(find, stringComparison)
  60.  
  61.    While (firstIndex <= lastIndex)
  62.        Dim findIndex As Integer = rtb.Find(find, firstIndex, textLength, richTextBoxFinds)
  63.        If (findIndex <> -1) Then
  64.            successCount += 1
  65.        Else
  66.            Continue While
  67.        End If
  68.  
  69.        rtb.SelectionColor = foreColor
  70.        rtb.SelectionBackColor = backColor
  71.        rtb.SelectionFont = font
  72.  
  73.        firstIndex = (rtb.Text.IndexOf(find, findIndex, stringComparison) + 1)
  74.    End While ' (firstIndex <= lastIndex)
  75.  
  76.    ' Restore the caret position. Reset selection length to zero.
  77.    rtb.Select(caretPosition, length:=0)
  78.  
  79.    Return successCount
  80.  
  81. End Function



Ese código de arriba resolvería el problema, con eso ya está, así que si lo prefieres puedes no seguir leyendo nada más de este comentario, pero si quieres aprender cosas nuevas entonces sigue leyendo...

...Para implementar las funcionalidades de búsqueda y resaltado de palabras, para hacerlo decentemente quiero decir, lo más apropiado sería empezar por bloquear temporálmente los mensajes de ventana de dibujado de la ventana del control afectado para optimizar (acelerar) el procedimiento de ejecución, y de paso al mismo tiempo intentar evitar indiseados efectos de flickering.

Bueno, ya que lo has intentado hacer por ti mismo, te voy a mostrar un ejemplo completo y funcional. Para hacerlo funcionar simplemente debes copia y pegar cada bloque de código que iré mostrando, en una nueva clase por cada bloque de código (pero no seas vago, lee algo del código para intentar aprender buenos hábitos de programación .NET). Si no entiendes algo, pregúntalo.

Debido al límite de caracteres del foro, me he visto obligado a recortar mucho código para eliminar practicamente casi toda la documentación XML...

Sin embargo, para hacerlo todo más facil y comprensible, abajo del todo de esta respuesta te dejo un proyecto hecho en Visual Studio 2017 con el código y su documentación al completo y que además contiene esta pequeña aplicación para demostrar la funcionalidad de búsqueda y resaltado de palabras:



También cabe mencionar que el código fuente de aquí abajo solo provee la funcionalidad de "Buscar todas las ocurrencias", pero no provee la funcionalidad de "Buscar siguiente palabra" hacia arriba/abajo etc, aunque si que tengo implementadas ese tipo de funciones en mi librería comercial... pero tampoco voy a regalarlo todo hecho, así que me limito a resolver la duda en concreto de "¿cómo buscar y colorear todas las ocurrencias de un string?".



NOTA INFORMATIVA:
---
EL SIGUIENTE CÓDIGO HA SIDO EXTRAIDO Y OFRECIDO DE FORMA GRATUITA A PARTIR DE MI FRAMEWORK COMERCIAL ELEKTROKIT FRAMEWORK , EL CUAL CONTIENE UNA INFINIDAD DE UTILIDADES ENFOCADAS A UNA AMPLIA VARIEDAD DE TEMÁTICAS Y ESCENARIOS EN LA PROGRAMACIÓN .NET, COMO ÉSTE. SI QUIEREN CONOCER MÁS ACERCA DEL PRODUCTO, PUEDEN ENCONTRARLO EN MI FIRMA DE USUARIO DEL FORO.
ESTE CÓDIGO SE PUEDE USAR Y MODIFICAR DE FORMA LIBRE COMO LES APETEZCA.

---




WindowsMessages.vb

Código
  1. #Region " Windows Messages "
  2.  
  3. Namespace ElektroKit.Interop.Win32
  4.  
  5.    ' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927%28v=vs.85%29.aspx
  6.    Friend Enum WindowsMessages As Integer
  7.        ' http://msdn.microsoft.com/en-us/library/windows/desktop/dd145219%28v=vs.85%29.aspx
  8.        WM_SetRedraw = &HB
  9.    End Enum
  10.  
  11. End Namespace
  12.  
  13. #End Region



RedrawWindowFlags.vb

Código
  1. #Region " RedrawWindowFlags "
  2.  
  3. Namespace ElektroKit.Interop.Win32
  4.  
  5.    ' http://msdn.microsoft.com/en-us/library/windows/desktop/dd162911%28v=vs.85%29.aspx
  6.    <Flags>
  7.    Friend Enum RedrawWindowFlags As Integer
  8.        Invalidate = &H1
  9.        InternalPaint = &H2
  10.        [Erase] = &H4
  11.        Validate = &H8
  12.        NoInternalPaint = &H10
  13.        NoErase = &H20
  14.        NoChildren = &H40
  15.        AllChildren = &H80
  16.        UpdateNow = &H100
  17.        EraseNow = &H200
  18.        Frame = &H400
  19.        NoFrame = &H800
  20.    End Enum
  21.  
  22. End Namespace
  23.  
  24. #End Region



NativeMethods.vb

Código
  1. #Region " Imports "
  2.  
  3. Imports System.ComponentModel
  4. Imports System.Diagnostics
  5. Imports System.Runtime.InteropServices
  6. Imports System.Security
  7.  
  8. #End Region
  9.  
  10. #Region " NativeMethods "
  11.  
  12. Namespace ElektroKit.Interop.Win32
  13.  
  14.    ' http://msdn.microsoft.com/en-us/library/ms182161.aspx
  15.    Friend NotInheritable Class NativeMethods ' NOT <SuppressUnmanagedCodeSecurity>
  16.  
  17. #Region " Constructors "
  18.  
  19.        <DebuggerNonUserCode>
  20.        Private Sub New()
  21.        End Sub
  22.  
  23. #End Region
  24.  
  25. #Region " User32.dll "
  26.  
  27.        ' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950%28v=vs.85%29.aspx
  28.        <DllImport("User32.dll", SetLastError:=True)>
  29.        Friend Shared Function SendMessage(ByVal hwnd As IntPtr,
  30.                                           ByVal msg As Integer,
  31.                                           ByVal wParam As IntPtr,
  32.                                           ByVal lParam As IntPtr
  33.        ) As IntPtr
  34.        End Function
  35.  
  36.        ' http://msdn.microsoft.com/en-us/library/windows/desktop/dd162911%28v=vs.85%29.aspx
  37.        <DllImport("User32.dll")>
  38.        Friend Shared Function RedrawWindow(ByVal hwnd As IntPtr,
  39.                                            ByVal lprcUpdate As IntPtr,
  40.                                            ByVal hrgnUpdate As IntPtr,
  41.                                            ByVal flags As RedrawWindowFlags
  42.        ) As <MarshalAs(UnmanagedType.Bool)> Boolean
  43.        End Function
  44.  
  45. #End Region
  46.  
  47.    End Class
  48.  
  49. End Namespace
  50.  
  51. #End Region



IWin32Window_Extensions.vb

Código
  1. #Region " Imports "
  2.  
  3. Imports System.ComponentModel
  4. Imports System.Diagnostics
  5. Imports System.Drawing
  6. Imports System.Runtime.CompilerServices
  7.  
  8. Imports ElektroKit.Interop.Win32
  9.  
  10. Imports WinForms = System.Windows.Forms
  11.  
  12. #End Region
  13.  
  14. #Region " IWin32Window Extensions "
  15.  
  16. Namespace ElektroKit.Extensions.[IWin32Window]
  17.  
  18.    ''' <summary>
  19.    ''' Provides custom extension methods to use with <see cref="WinForms.IWin32Window"/> type.
  20.    ''' </summary>
  21.    <HideModuleName>
  22.    Public Module Drawing
  23.  
  24. #Region " Public Extension Methods "
  25.  
  26.        ''' <summary>
  27.        ''' Prevents the specified window from being redrawn.
  28.        ''' <para></para>
  29.        ''' By calling this method, it will disallow painting events from firing on the specified window.
  30.        ''' </summary>
  31.        <DebuggerStepThrough>
  32.        <Extension>
  33.        <EditorBrowsable(EditorBrowsableState.Always)>
  34.        Public Sub SuspendDrawing(ByVal sender As WinForms.IWin32Window)
  35.            NativeMethods.SendMessage(sender.Handle, WindowsMessages.WM_SetRedraw, IntPtr.Zero, IntPtr.Zero)
  36.        End Sub
  37.  
  38.        ''' <summary>
  39.        ''' Allow the specified window to be redrawn.
  40.        ''' <para></para>
  41.        ''' By calling this method, it will allow painting events to be fired on the specified window.
  42.        ''' </summary>
  43.        <DebuggerStepThrough>
  44.        <Extension>
  45.        <EditorBrowsable(EditorBrowsableState.Always)>
  46.        Public Sub ResumeDrawing(ByVal sender As WinForms.IWin32Window)
  47.            Drawing.ResumeDrawing(sender, True)
  48.        End Sub
  49.  
  50.        ''' <summary>
  51.        ''' Allow the specified window to be redrawn.
  52.        ''' <para></para>
  53.        ''' By calling this method, it will allow painting events to be fired on the specified window.
  54.        ''' </summary>
  55.        ''' <param name="redraw">
  56.        ''' If set to <see langword="True"/>, causes the window to de redrawn
  57.        ''' (similarly as calling <see cref="WinForms.Control.Refresh()"/> method).
  58.        ''' </param>
  59.        <DebuggerStepThrough>
  60.        <Extension>
  61.        <EditorBrowsable(EditorBrowsableState.Always)>
  62.        Public Sub ResumeDrawing(ByVal sender As WinForms.IWin32Window, ByVal redraw As Boolean)
  63.            NativeMethods.SendMessage(sender.Handle, WindowsMessages.WM_SetRedraw, New IntPtr(1), IntPtr.Zero)
  64.            If (redraw) Then
  65.                NativeMethods.RedrawWindow(sender.Handle, IntPtr.Zero, IntPtr.Zero,
  66.                                           RedrawWindowFlags.Frame Or
  67.                                           RedrawWindowFlags.UpdateNow Or
  68.                                           RedrawWindowFlags.Invalidate)
  69.            End If
  70.        End Sub
  71.  
  72. #End Region
  73.  
  74.    End Module
  75.  
  76. End Namespace
  77.  
  78. #End Region



RichTextBox_Extensions.vb

Código
  1. #Region " Imports "
  2.  
  3. Imports System.ComponentModel
  4. Imports System.Drawing
  5. Imports System.Runtime.CompilerServices
  6. Imports System.Text.RegularExpressions
  7.  
  8. Imports WinForms = System.Windows.Forms
  9.  
  10. #End Region
  11.  
  12. #Region " RichTextBox Extensions "
  13.  
  14. Namespace ElektroKit.Extensions.[RichTextBox]
  15.  
  16.    ''' <summary>
  17.    ''' Provides custom extension methods to use with <see cref="WinForms.RichTextBox"/> control.
  18.    ''' </summary>
  19.    <HideModuleName>
  20.    Public Module WordFinding
  21.  
  22. #Region " Public Extension Methods "
  23.  
  24. #Region " Strings "
  25.  
  26.        <DebuggerStepThrough>
  27.        <Extension>
  28.        <EditorBrowsable(EditorBrowsableState.Always)>
  29.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  30.                                        ByVal find As String, ByVal ignoreCase As Boolean,
  31.                                        ByVal foreColor As Global.System.Drawing.Color) As Integer
  32.  
  33.            Return WordFinding.InternalColorizeMatches(sender, {find}, ignoreCase, foreColor, Nothing, Nothing)
  34.  
  35.        End Function
  36.  
  37.        <DebuggerStepThrough>
  38.        <Extension>
  39.        <EditorBrowsable(EditorBrowsableState.Always)>
  40.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  41.                                        ByVal find As String, ByVal ignoreCase As Boolean,
  42.                                        ByVal foreColor As Global.System.Drawing.Color,
  43.                                        ByVal backColor As Global.System.Drawing.Color) As Integer
  44.  
  45.            Return WordFinding.InternalColorizeMatches(sender, {find}, ignoreCase, foreColor, backColor, Nothing)
  46.  
  47.        End Function
  48.  
  49.        ''' <summary>
  50.        ''' Matches all the occurrences of the specified string in the source <see cref="WinForms.RichTextBox"/>
  51.        ''' and set the foreground color, background color, and the font of any occurrence found.
  52.        ''' </summary>
  53.        <DebuggerStepThrough>
  54.        <Extension>
  55.        <EditorBrowsable(EditorBrowsableState.Always)>
  56.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  57.                                        ByVal find As String, ByVal ignoreCase As Boolean,
  58.                                        ByVal foreColor As Global.System.Drawing.Color,
  59.                                        ByVal backColor As Global.System.Drawing.Color,
  60.                                        ByVal font As Font) As Integer
  61.  
  62.            Return WordFinding.InternalColorizeMatches(sender, {find}, ignoreCase, foreColor, backColor, font)
  63.  
  64.        End Function
  65.  
  66.        <DebuggerStepThrough>
  67.        <Extension>
  68.        <EditorBrowsable(EditorBrowsableState.Always)>
  69.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  70.                                        ByVal find As String(), ByVal ignoreCase As Boolean,
  71.                                        ByVal foreColor As Global.System.Drawing.Color) As Integer
  72.  
  73.            Return WordFinding.InternalColorizeMatches(sender, find, ignoreCase, foreColor, Nothing, Nothing)
  74.  
  75.        End Function
  76.  
  77.        <DebuggerStepThrough>
  78.        <Extension>
  79.        <EditorBrowsable(EditorBrowsableState.Always)>
  80.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  81.                                        ByVal find As String(), ByVal ignoreCase As Boolean,
  82.                                        ByVal foreColor As Global.System.Drawing.Color,
  83.                                        ByVal backColor As Global.System.Drawing.Color) As Integer
  84.  
  85.            Return WordFinding.InternalColorizeMatches(sender, find, ignoreCase, foreColor, backColor, Nothing)
  86.  
  87.        End Function
  88.  
  89.        ''' <summary>
  90.        ''' Matches all the occurrences of the specified strings in the source <see cref="WinForms.RichTextBox"/>
  91.        ''' and set the foreground color, background color, and the font of any occurrence found.
  92.        ''' </summary>
  93.        <DebuggerStepThrough>
  94.        <Extension>
  95.        <EditorBrowsable(EditorBrowsableState.Always)>
  96.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  97.                                        ByVal find As String(), ByVal ignoreCase As Boolean,
  98.                                        ByVal foreColor As Global.System.Drawing.Color,
  99.                                        ByVal backColor As Global.System.Drawing.Color,
  100.                                        ByVal font As Font) As Integer
  101.  
  102.            Return WordFinding.InternalColorizeMatches(sender, find, ignoreCase, foreColor, backColor, font)
  103.  
  104.        End Function
  105.  
  106. #End Region
  107.  
  108. #Region " Regular Expressions "
  109.  
  110.        <DebuggerStepThrough>
  111.        <Extension>
  112.        <EditorBrowsable(EditorBrowsableState.Always)>
  113.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  114.                                        ByVal find As Regex,
  115.                                        ByVal foreColor As Global.System.Drawing.Color) As Integer
  116.  
  117.            Return WordFinding.InternalColorizeMatches(sender, {find}, foreColor, Nothing, Nothing)
  118.  
  119.        End Function
  120.  
  121.        <DebuggerStepThrough>
  122.        <Extension>
  123.        <EditorBrowsable(EditorBrowsableState.Always)>
  124.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  125.                                        ByVal find As Regex,
  126.                                        ByVal foreColor As Global.System.Drawing.Color,
  127.                                        ByVal backColor As Global.System.Drawing.Color) As Integer
  128.  
  129.            Return WordFinding.InternalColorizeMatches(sender, {find}, foreColor, backColor, Nothing)
  130.  
  131.        End Function
  132.  
  133.        ''' <summary>
  134.        ''' Matches all the occurrences of the specified regular expression in the source <see cref="WinForms.RichTextBox"/>
  135.        ''' and set the foreground color, background color, and the font of any occurrence found.
  136.        ''' </summary>
  137.        <DebuggerStepThrough>
  138.        <Extension>
  139.        <EditorBrowsable(EditorBrowsableState.Always)>
  140.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  141.                                        ByVal find As Regex,
  142.                                        ByVal foreColor As Global.System.Drawing.Color,
  143.                                        ByVal backColor As Global.System.Drawing.Color,
  144.                                        ByVal font As Font) As Integer
  145.  
  146.            Return WordFinding.InternalColorizeMatches(sender, {find}, foreColor, backColor, font)
  147.  
  148.        End Function
  149.  
  150.        <DebuggerStepThrough>
  151.        <Extension>
  152.        <EditorBrowsable(EditorBrowsableState.Always)>
  153.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  154.                                        ByVal find As Regex(),
  155.                                        ByVal foreColor As Global.System.Drawing.Color) As Integer
  156.  
  157.            Return WordFinding.InternalColorizeMatches(sender, find, foreColor, Nothing, Nothing)
  158.  
  159.        End Function
  160.  
  161.        <DebuggerStepThrough>
  162.        <Extension>
  163.        <EditorBrowsable(EditorBrowsableState.Always)>
  164.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  165.                                        ByVal find As Regex(),
  166.                                        ByVal foreColor As Global.System.Drawing.Color,
  167.                                        ByVal backColor As Global.System.Drawing.Color) As Integer
  168.  
  169.            Return WordFinding.InternalColorizeMatches(sender, find, foreColor, backColor, Nothing)
  170.  
  171.        End Function
  172.  
  173.        ''' <summary>
  174.        ''' Matches all the occurrences of any of the specified regular expressions in the source <see cref="WinForms.RichTextBox"/>
  175.        ''' and set the foreground color, background color, and the font of any occurrence found.
  176.        ''' </summary>
  177.        <DebuggerStepThrough>
  178.        <Extension>
  179.        <EditorBrowsable(EditorBrowsableState.Always)>
  180.        Public Function ColorizeMatches(ByVal sender As WinForms.RichTextBox,
  181.                                        ByVal find As Regex(),
  182.                                        ByVal foreColor As Global.System.Drawing.Color,
  183.                                        ByVal backColor As Global.System.Drawing.Color,
  184.                                        ByVal font As Font) As Integer
  185.  
  186.            Return WordFinding.InternalColorizeMatches(sender, find, foreColor, backColor, font)
  187.  
  188.        End Function
  189.  
  190.        ''' <summary>
  191.        ''' Matches all the occurrences of the specified regular expression in the source <see cref="WinForms.RichTextBox"/>
  192.        ''' and invokes the specified action for any occurrence found.
  193.        ''' </summary>
  194.        <DebuggerStepThrough>
  195.        <Extension>
  196.        <EditorBrowsable(EditorBrowsableState.Always)>
  197.        Public Sub IterateMatches(ByVal sender As WinForms.RichTextBox,
  198.                                  ByVal find As Regex,
  199.                                  ByVal action As Action(Of WinForms.RichTextBox, Match))
  200.  
  201.            WordFinding.InternalIterateMatches(sender, {find}, action)
  202.  
  203.        End Sub
  204.  
  205.        <DebuggerStepThrough>
  206.        <Extension>
  207.        <EditorBrowsable(EditorBrowsableState.Always)>
  208.        Public Sub IterateMatches(ByVal sender As WinForms.RichTextBox,
  209.                                  ByVal find As Regex(),
  210.                                  ByVal action As Action(Of WinForms.RichTextBox, Match))
  211.  
  212.            WordFinding.InternalIterateMatches(sender, find, action)
  213.  
  214.        End Sub
  215.  
  216. #End Region
  217.  
  218. #End Region
  219.  
  220. #Region " Private Methods "
  221.  
  222.        ''' <summary>
  223.        ''' Find all the occurrences of the specified strings in the source <see cref="WinForms.RichTextBox"/>
  224.        ''' and set the foreground color, background color, and the font of any occurrence found.
  225.        ''' </summary>
  226.        ''' <returns>
  227.        ''' Returns the total amount of occurrences found.
  228.        ''' </returns>
  229.        <DebuggerStepThrough>
  230.        Private Function InternalColorizeMatches(ByVal sender As WinForms.RichTextBox,
  231.                                                 ByVal find As String(), ByVal ignoreCase As Boolean,
  232.                                                 ByVal foreColor As Global.System.Drawing.Color,
  233.                                                 ByVal backColor As Global.System.Drawing.Color,
  234.                                                 ByVal font As Font) As Integer
  235.  
  236.            If (foreColor = Nothing) OrElse (foreColor = Color.Empty) Then
  237.                foreColor = sender.ForeColor
  238.            End If
  239.  
  240.            If (backColor = Nothing) OrElse (backColor = Color.Empty) Then
  241.                backColor = sender.BackColor
  242.            End If
  243.  
  244.            If (font Is Nothing) Then
  245.                font = sender.Font
  246.            End If
  247.  
  248.    ' Set letter-case criteria.
  249.    Dim richTextBoxFinds As RichTextBoxFinds =
  250.        If(ignoreCase, RichTextBoxFinds.None, RichTextBoxFinds.MatchCase)
  251.    Dim stringComparison As StringComparison =
  252.        If(ignoreCase, StringComparison.OrdinalIgnoreCase, StringComparison.Ordinal)
  253.  
  254.            ' Save the current caret position to restore it at the end.
  255.            Dim caretPosition As Integer = sender.SelectionStart
  256.  
  257.            ' Suspend the control layout logic. And suspend painting events from firing.
  258.            sender.SuspendLayout()
  259.            ElektroKit.Extensions.IWin32Window.SuspendDrawing(sender)
  260.  
  261.            ' Colorize the matches.
  262.            Dim successCount As Integer = 0
  263.            Dim textLength As Integer = sender.TextLength
  264.            For Each s As String In find
  265.  
  266.                If String.IsNullOrEmpty(s) Then
  267.                    Continue For
  268.                End If
  269.  
  270.                Dim firstIndex As Integer = 0
  271.                Dim lastIndex As Integer = sender.Text.LastIndexOf(s, stringComparison)
  272.  
  273.                While (firstIndex <= lastIndex)
  274.                    Dim findIndex As Integer = sender.Find(s, firstIndex, textLength, richTextBoxFinds)
  275.                    If (findIndex <> -1) Then
  276.                        successCount += 1
  277.                    Else
  278.                        Continue While
  279.                    End If
  280.  
  281.                    sender.SelectionColor = foreColor
  282.                    sender.SelectionBackColor = backColor
  283.                    sender.SelectionFont = font
  284.  
  285.                    firstIndex = (sender.Text.IndexOf(s, findIndex, stringComparison) + 1)
  286.                End While ' (firstIndex <= lastIndex)
  287.  
  288.            Next s
  289.  
  290.            ' Restore the caret position. Reset selection length to zero.
  291.            sender.Select(caretPosition, length:=0)
  292.  
  293.            ' Restore the control layout logic. And resume painting events.
  294.            sender.ResumeLayout()
  295.            ElektroKit.Extensions.IWin32Window.ResumeDrawing(sender, redraw:=True)
  296.  
  297.            Return successCount
  298.  
  299.        End Function
  300.  
  301.        ''' <summary>
  302.        ''' Find all the occurrences of the specified regular expressions in the source <see cref="WinForms.RichTextBox"/>
  303.        ''' and set the foreground color, background color, and the font of any occurrence found.
  304.        ''' </summary>
  305.        ''' <returns>
  306.        ''' Returns the total amount of occurrences found.
  307.        ''' </returns>
  308.        <DebuggerStepThrough>
  309.        Private Function InternalColorizeMatches(ByVal sender As WinForms.RichTextBox,
  310.                                                 ByVal find As Regex(),
  311.                                                 ByVal foreColor As Global.System.Drawing.Color,
  312.                                                 ByVal backColor As Global.System.Drawing.Color,
  313.                                                 ByVal font As Font) As Integer
  314.  
  315.            If (foreColor = Nothing) OrElse (foreColor = Color.Empty) Then
  316.                foreColor = sender.ForeColor
  317.            End If
  318.  
  319.            If (backColor = Nothing) OrElse (backColor = Color.Empty) Then
  320.                backColor = sender.BackColor
  321.            End If
  322.  
  323.            If (font Is Nothing) Then
  324.                font = sender.Font
  325.            End If
  326.  
  327.            ' Save the current caret position to restore it at the end.
  328.            Dim caretPosition As Integer = sender.SelectionStart
  329.  
  330.            ' Suspend the control layout logic. And suspend painting events from firing.
  331.            sender.SuspendLayout()
  332.            ElektroKit.Extensions.IWin32Window.SuspendDrawing(sender)
  333.  
  334.            ' Colorize the matches.
  335.            Dim successCount As Integer = 0
  336.            For Each rgx As Regex In find
  337.  
  338.                Dim matches As MatchCollection = rgx.Matches(sender.Text, rgx.Options)
  339.                successCount += matches.Count
  340.  
  341.                For Each m As Match In matches
  342.                    sender.Select(m.Index, m.Length)
  343.                    sender.SelectionColor = foreColor
  344.                    sender.SelectionBackColor = backColor
  345.                    sender.SelectionFont = font
  346.                Next m
  347.  
  348.            Next rgx
  349.  
  350.            ' Restore the caret position. Reset selection length to zero.
  351.            sender.Select(caretPosition, length:=0)
  352.  
  353.            ' Restore the control layout logic. And resume painting events.
  354.            sender.ResumeLayout()
  355.            ElektroKit.Extensions.IWin32Window.ResumeDrawing(sender, redraw:=True)
  356.  
  357.            Return successCount
  358.  
  359.        End Function
  360.  
  361.        ''' <summary>
  362.        ''' Matches all the occurrences of the specified regular expression in the source <see cref="WinForms.RichTextBox"/>
  363.        ''' and invokes the specified action for any occurrence found.
  364.        ''' </summary>
  365.        <DebuggerStepThrough>
  366.        Private Sub InternalIterateMatches(ByVal sender As WinForms.RichTextBox,
  367.                                           ByVal find As Regex(),
  368.                                           ByVal action As Action(Of WinForms.RichTextBox, Match))
  369.  
  370.            ' Suspend the control layout logic. And suspend painting events from firing.
  371.            sender.SuspendLayout()
  372.            ElektroKit.Extensions.IWin32Window.SuspendDrawing(sender)
  373.  
  374.            ' Iterate the matches.
  375.            For Each rgx As Regex In find
  376.                Dim matches As MatchCollection = rgx.Matches(sender.Text, rgx.Options)
  377.  
  378.                For Each m As Match In matches
  379.                    action.Invoke(sender, m)
  380.                Next m
  381.            Next rgx
  382.  
  383.            ' Restore the control layout logic. And resume painting events.
  384.            sender.ResumeLayout()
  385.            ElektroKit.Extensions.IWin32Window.ResumeDrawing(sender, redraw:=True)
  386.  
  387.        End Sub
  388.  
  389. #End Region
  390.  
  391.    End Module
  392.  
  393. End Namespace
  394.  
  395. #End Region



EJEMPLOS DE USO REAL-WORLD

Form1.vb

Código
  1. Class Form1
  2.  
  3.    ' ...
  4.  
  5.    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  6.  
  7.        Dim rtb As RichTextBox = Me.RichTextBox1
  8.  
  9.        ' Reset selection.
  10.        With rtb
  11.            .SelectAll()
  12.            .SelectionColor = .ForeColor
  13.            .SelectionBackColor = .BackColor
  14.            .SelectionFont = .Font
  15.            .Select(0, 0)
  16.        End With
  17.  
  18.        ' Perform a new selection.
  19.        Dim find As String = Me.TextBox1.Text ' The text to find.
  20.        Dim ignoreCase As Boolean = Me.CheckBox1.Checked
  21.        Dim forecolor As Color = Color.LimeGreen
  22.        Dim backcolor As Color = rtb.SelectionBackColor
  23.        Dim font As Font = rtb.SelectionFont
  24.  
  25.        Dim occurrences As Integer = rtb.ColorizeMatches(find, ignoreCase, forecolor, backcolor, font)
  26.        Me.Label1.Text = String.Format("{0} occurrences", occurrences)
  27.  
  28.    End Sub
  29.  
  30.    ' ...
  31.  
  32. End Class

EJEMPLOS DE USO DE LAS SOBRECARGAS PARA STRING

Código
  1. Dim find As String = "Hello World"
  2. Dim forecolor As Color = Color.Red
  3.  
  4. RichTextBox1.ColorizeMatches(find, True, forecolor)

Código
  1. Dim find As String = "Hello World"
  2. Dim forecolor As Color = Color.Red
  3. Dim backcolor As Color = Color.Black
  4.  
  5. RichTextBox1.ColorizeMatches(find, True, forecolor, backcolor)

Código
  1. Dim find As String = "Hello World"
  2. Dim forecolor As Color = Color.Red
  3. Dim backcolor As Color = Color.Black
  4. Dim font As New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Italic)
  5.  
  6. RichTextBox1.ColorizeMatches(find, True, forecolor, backcolor, font)

Código
  1. Dim find As String() = {"Hello", "World"}
  2. Dim forecolor As Color = Color.Red
  3.  
  4. RichTextBox1.ColorizeMatches(find, True, forecolor)

Código
  1. Dim find As String() = {"Hello", "World"}
  2. Dim forecolor As Color = Color.Red
  3. Dim backcolor As Color = Color.Black
  4.  
  5. RichTextBox1.ColorizeMatches(find, True, forecolor, backcolor)

Código
  1. Dim find As String() = {"Hello", "World"}
  2. Dim forecolor As Color = Color.Red
  3. Dim backcolor As Color = Color.Black
  4. Dim font As New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Italic)
  5.  
  6. RichTextBox1.ColorizeMatches(find, True, forecolor, backcolor, font)

EJEMPLOS DE USO DE LAS SOBRECARGAS PARA EXPRESIONES REGULARES

Código
  1. Dim find As New Regex("[0-9]", RegexOptions.None)
  2. Dim forecolor As Color = Color.Red
  3.  
  4. RichTextBox1.ColorizeMatches(rgx, forecolor)

Código
  1. Dim find As New Regex("[0-9]", RegexOptions.None)
  2. Dim forecolor As Color = Color.Red
  3. Dim backcolor As Color = Color.Black
  4.  
  5. RichTextBox1.ColorizeMatches(rgx, forecolor, backcolor)

Código
  1. Dim find As New Regex("[0-9]", RegexOptions.None)
  2. Dim forecolor As Color = Color.Red
  3. Dim backcolor As Color = Color.Black
  4. Dim font As New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Italic)
  5.  
  6. RichTextBox1.ColorizeMatches(rgx, forecolor, backcolor, font)

Código
  1. Dim rgx1 As New Regex("[0-9]", RegexOptions.None)
  2. Dim rgx2 As New Regex("[a-z]", RegexOptions.None)
  3. Dim forecolor As Color = Color.Red
  4.  
  5. RichTextBox1.ColorizeMatches({rgx1, rgx2}, forecolor)

Código
  1. Dim rgx1 As New Regex("[0-9]", RegexOptions.None)
  2. Dim rgx2 As New Regex("[a-z]", RegexOptions.None)
  3. Dim forecolor As Color = Color.Red
  4. Dim backcolor As Color = Color.Black
  5.  
  6. RichTextBox1.ColorizeMatches({rgx1, rgx2}, forecolor, backcolor)

Código
  1. Dim rgx1 As New Regex("[0-9]", RegexOptions.None)
  2. Dim rgx2 As New Regex("[a-z]", RegexOptions.None)
  3. Dim forecolor As Color = Color.Red
  4. Dim backcolor As Color = Color.Black
  5. Dim font As New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Italic)
  6.  
  7. RichTextBox1.ColorizeMatches({rgx1, rgx2}, forecolor, backcolor, font)

Código
  1. Dim rgx As New Regex("[0-9]", RegexOptions.None)
  2. Dim forecolor As Color = Color.Red
  3. Dim backcolor As Color = Color.Black
  4. Dim font As New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Italic)
  5.  
  6. Dim action As New Action(Of RichTextBox, Match)(
  7.    Sub(rtb As RichTextBox, m As Match)
  8.        With rtb
  9.            .Select(m.Index, m.Length)
  10.            .SelectionColor = forecolor
  11.            .SelectionBackColor = backcolor
  12.            .SelectionFont = font
  13.        End With
  14.    End Sub)
  15.  
  16. RichTextBox1.IterateMatches(rgx, action)

Código
  1. Dim rgx1 As New Regex("[0-9]", RegexOptions.None)
  2. Dim rgx2 As New Regex("[a-z]", RegexOptions.None)
  3. Dim forecolor As Color = Color.Red
  4. Dim backcolor As Color = Color.Black
  5. Dim font As New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Italic)
  6.  
  7. Dim action As New Action(Of RichTextBox, Match)(
  8.    Sub(rtb As RichTextBox, m As Match)
  9.        With rtb
  10.            .Select(m.Index, m.Length)
  11.            .SelectionColor = forecolor
  12.            .SelectionBackColor = backcolor
  13.            .SelectionFont = font
  14.        End With
  15.    End Sub)
  16.  
  17. RichTextBox1.IterateMatches({rgx1, rgx2}, action)



SOLUCIÓN PARA VISUAL STUDIO 2017

( contiene todo el código fuente de arriba, documentado al completo. )



Nota: los colores de texto y fondo de los controles no se verán igual que en la imagen GIF de arriba, así que es probable que necesiten ajustar dichos colores.


« Última modificación: 27 Noviembre 2017, 17:29 pm por Eleкtro » En línea

**Aincrad**


Desconectado Desconectado

Mensajes: 668



Ver Perfil WWW
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #2 en: 27 Noviembre 2017, 19:10 pm »

Gracias por respoender Elektro .

en internet encontre este codigo que me busca y subralla la palabra que busco en un RichTextbox .

code que encontre en internet:

Código
  1. Dim TEMPORAL As String = RichTextBox1.Text
  2.        RichTextBox1.Clear()
  3.        RichTextBox1.Text = TEMPORAL
  4.        Try
  5.            Dim BUSQUEDA As String = InputBox("BUSCAR")
  6.            Dim INDEX As Integer
  7.            While INDEX < RichTextBox1.Text.LastIndexOf(BUSQUEDA)
  8.                RichTextBox1.Find(BUSQUEDA, INDEX, RichTextBox1.TextLength, RichTextBoxFinds.None)
  9.                RichTextBox1.SelectionBackColor = Color.DarkBlue
  10.                INDEX = RichTextBox1.Text.IndexOf(BUSQUEDA, INDEX) + 1
  11.            End While
  12.        Catch ex As Exception
  13.            MsgBox(ex.Message)
  14.        End Try


Pero el Tu codigo esta SUPER . pero al intentar abrirlo con mi vb 2010 me salen miles de errores .


bueno pase el code importante a un boton de mi proyecto pero me sale 1 error .


aqui te dejo el code que extraje y puse en mi proyecto.


Código
  1. Dim rtb As RichTextBox = Me.RichTextBox1
  2.  
  3.        ' Reset selection.
  4.        With rtb
  5.            .SelectAll()
  6.            .SelectionColor = .ForeColor
  7.            .SelectionBackColor = .BackColor
  8.            .SelectionFont = .Font
  9.            .Select(0, 0)
  10.        End With
  11.  
  12.        ' Perform a new selection.
  13.        Dim find As String = Me.TextBox1.Text ' The text to find.
  14.        Dim ignoreCase As Boolean = Me.CheckBox1.Checked
  15.        Dim forecolor As Color = Color.LimeGreen
  16.        Dim backcolor As Color = rtb.SelectionBackColor
  17.        Dim font As Font = rtb.SelectionFont
  18.  
  19.        Dim occurrences As Integer = rtb.ColorizeMatches(find, ignoreCase, forecolor, backcolor, font)   ' HE AQUI EL ERROR ME DICE COLORIZEMATCHES NO ES UN MIENBRO DE SYSTEM.WINDOWS.FORM1.WINDOWSAPLICATION10
  20.        Me.Label1.Text = String.Format("{0} occurrences", occurrences)

EL ERROR ME DICE COLORIZEMATCHES NO ES UN MIENBRO DE SYSTEM.WINDOWS.FORM1.WINDOWSAPLICATION10
« Última modificación: 27 Noviembre 2017, 19:16 pm por **Aincrad** » En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #3 en: 27 Noviembre 2017, 19:53 pm »

en internet encontre este codigo que me busca y subralla la palabra que busco en un RichTextbox .

code que encontre en internet:

Código
  1. Dim TEMPORAL As String = RichTextBox1.Text
  2.        RichTextBox1.Clear()
  3.        RichTextBox1.Text = TEMPORAL
  4.        Try
  5.            Dim BUSQUEDA As String = InputBox("BUSCAR")
  6.            Dim INDEX As Integer
  7.            While INDEX < RichTextBox1.Text.LastIndexOf(BUSQUEDA)
  8.                RichTextBox1.Find(BUSQUEDA, INDEX, RichTextBox1.TextLength, RichTextBoxFinds.None)
  9.                RichTextBox1.SelectionBackColor = Color.DarkBlue
  10.                INDEX = RichTextBox1.Text.IndexOf(BUSQUEDA, INDEX) + 1
  11.            End While
  12.        Catch ex As Exception
  13.            MsgBox(ex.Message)
  14.        End Try

Ese código está mal, esta evaluación es incorrecta:
Citar
Código
  1. While INDEX < RichTextBox1.Text.LastIndexOf(BUSQUEDA)

...piensa que ocurrirá si el índice es Cero, es decir, si la palabra que quieres buscar está en la posición 0 (dicho de otra forma: justo al principio). Ese algoritmo no lo "procesará".

Puedes hacer la prueba por ti mismo, escribe solo una letra en el RichTextBox, e intenta buscarla/resaltarla con ese código que cojiste por Internet.

La solución es facil:
Código
  1. While INDEX <= RichTextBox1.Text.LastIndexOf(BUSQUEDA)

Pero de todas formas no tienes la necesidad de buscar en Internet, al principio de mi comentario te puse una función sencillita y de uso genérico que puedes usar, ¿has intentado usarla?, no requiere que copies nada más, solo esa función.



Pero el Tu codigo esta SUPER . pero al intentar abrirlo con mi vb 2010 me salen miles de errores .

Suena algo lógico, ya que basicamente estás intentando hacer un downgrade de VS2017 a VS2010. En VS2017 el archivo de solución de proyecto tiene campos que VS2010 no soporta (basicamente por que antes no existian), y luego están los cambios de sintaxis en las versiones de VB, y la versión máxima de .NET framework que puedas utilizar en VS2010... (el proyecto de VS2017 usa .NET Framework 4.6 o 4.7, no me fijé, pero es una de esas dos)

bueno pase el code importante a un boton de mi proyecto pero me sale 1 error .

aqui te dejo el code que extraje y puse en mi proyecto.

EL ERROR ME DICE COLORIZEMATCHES NO ES UN MIENBRO DE SYSTEM.WINDOWS.FORM1.WINDOWSAPLICATION10

Supongo que cuando dices "el código importante" no te estás refiriendo solo a ese bloque de código de 20 lineas que acabas de mostrar, ¿verdad?. El código importante son todos los trozos de código que mostré en mi otro comentario. La función ColorizeMatches está definida en la clase RichTextBox_Extensions.vb... una de las clases del "código importante" que te mostré.

Te compartí el proyecto de VS2017 precisamente para intentar evitarte este tipo de confusiones, para que vieras como debe quedar todo escrito. Mira, haz una cosa, en el proyecto de VS2017 hay unos archivos con extensión .vb:

  • .\WindowsApp1\Extensions\IWin32Window_Extensions.vb
  • .\WindowsApp1\Extensions\RichTextBox_Extensions.vb
  • .\WindowsApp1\Interop\NativeMethods.vb
  • .\WindowsApp1\Interop\RedrawWindowFlags.vb
  • .\WindowsApp1\Interop\WindowsMessages.vb

Simplemente copia el código de esos archivos en un nuevo proyecto de VS2010. Así te debería funcionar. Es decir, creas esos archivos en un proyecto de VS2010 y copias el código. No es necesario crear las carpetas "Extensions" e "Interop" ni tampoco que le pongas el mismo nombre a los archivos .vb

PD: quizás también quieras copiar el código del form:
  • .\WindowsApp1\Interop\Form1.vb

Saludos!
« Última modificación: 27 Noviembre 2017, 20:11 pm por Eleкtro » En línea

**Aincrad**


Desconectado Desconectado

Mensajes: 668



Ver Perfil WWW
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #4 en: 27 Noviembre 2017, 20:32 pm »

bueno he colocado cada clase a mi proyectos con su mismos nombres pero ahora me dice :

Código:
Error 1 'ColorizeMatches' no es un miembro de 'System.Windows.Forms.RichTextBox'.
« Última modificación: 27 Noviembre 2017, 20:40 pm por **Aincrad** » En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #5 en: 27 Noviembre 2017, 20:47 pm »

Si copiesta todo, entonces es un claro error de namespaces.

Donde te marque el error, reemplaza RichTextBox1.ColorizeMatches por NombrePrincipalDeTuNamespace.ElektroKit.Extensions.RichTextBox.ColorizeMatches. Es decir, escribe el espacio de nombres COMPLETO, y se arreglará.

Ejemplo:
Código
  1. Sub ...
  2.    NombrePrincipalDeTuNamespace.ElektroKit.Extensions.RichTextBox.ColorizeMatches(Richtextbox1, "buscar texto", ignoreCase, forecolor, backcolor, fuente)
  3. End Sub

Otra forma de solucionarlo: importa el namespace en la clase donde te marque el error. Ejemplo:

Código
  1. Imports NombrePrincipalDeTuNamespace.ElektroKit.Extensions.RichTextBox
  2.  
  3. Class Form1
  4. ...
  5.    Sub ...
  6.        RichTextBox1.ColorizeMatches("buscar texto", ignoreCase, forecolor, backcolor, fuente)
  7.    End Sub
  8. ...
  9. End Class

Claro yo no se como tienes puesto los nombres... pero creo que con eso te harás una idea.

Si no lo consigues arreglar por ti mismo, puedes pasarme el proyecto por mensaje privado o por aquí, y te lo arreglo.

Saludos
« Última modificación: 27 Noviembre 2017, 20:54 pm por Eleкtro » En línea

**Aincrad**


Desconectado Desconectado

Mensajes: 668



Ver Perfil WWW
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #6 en: 27 Noviembre 2017, 21:32 pm »

he hecho lo que me dices pero me salen mas errores . por eso te he mandado el proyecto por un mensaje privado. Perdoname por tantas molestias .  ;)
« Última modificación: 27 Noviembre 2017, 21:37 pm por **Aincrad** » En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #7 en: 27 Noviembre 2017, 21:47 pm »

En la clase Form1 añade esto:
Código
  1. Imports RICHTEXTBOX_NUMERAR.ElektroKit.Extensions.RichTextBox

En la clase Drawing, reemplaza esto:
Código
  1. Imports ElektroKit.Interop.Win32
por esto otro:
Código
  1. Imports RICHTEXTBOX_NUMERAR.ElektroKit.Interop.Win32

Así solucionas todos los errores.

saludos
En línea

**Aincrad**


Desconectado Desconectado

Mensajes: 668



Ver Perfil WWW
Re: Ayuda, buscar y resaltar la palabras de un RichTextBox
« Respuesta #8 en: 27 Noviembre 2017, 22:07 pm »

Gracias , todos los errores solucionados.

 ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-)
En línea



Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines