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

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Agregar palabras reservadas a un richtextbox
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Agregar palabras reservadas a un richtextbox  (Leído 4,453 veces)
nolasco281


Desconectado Desconectado

Mensajes: 319


Ver Perfil
Agregar palabras reservadas a un richtextbox
« en: 7 Marzo 2016, 19:30 pm »

Hola como estan.

El dia de hoy me entro una duda mientras usaba vb.net y esta es si existe alguna libreria que pueda aplicar a un richtextbox que me tomara palabras reservadas del lenguaje de programacion es decir si escribo en el richtextbox

vb.net
Código
  1. Dim variable as String

o si escribiese

java
Código
  1. int variable;

no se si me doy a entender lo que quisiera saber es si existe una libreria o algo de como hacer este tipo de cosas.

Algo asi como etiqueta geshi que pone de color las palabras reservadas

Espero puedan orientarme saludos.


« Última modificación: 7 Marzo 2016, 19:32 pm por nolasco281 » En línea

Lo que se puede imaginar... se puede programar.
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Agregar palabras reservadas a un richtextbox
« Respuesta #1 en: 7 Marzo 2016, 21:59 pm »

Desarrollar el algoritmo léxico por ti mismo sería una locura que llevaría demasiado tiempo, en mi opinión haces muy bien en preguntar por una librería ya desarrollada, puesto que existen algunas con años de experiencia en ese tema, muy, muy veteranas, como el wrapper de Scintilla para .Net:

En mi opinión no hay nada mejor, eso si, la plantilla de colores de "X" lenguaje es responsabilidad tuya constuirla a tu gusto... aquí tienes algunos ejemplos:

Otra opción sería FastcoloredTextBox, es lo que yo usaba antes de conocer Scintilla, y sinceramente ...es bueno, no hay que construir plantillas, pero el comportamiento y el acabado del control deja mucho que desear.

Y si solamente quieres colorear un código de una manera eficiente pero sin un control de usuario por medio, entonces puedes utilizar la librería ColorCode:

...Aunque el string resultante de ColorCode está en Html, así que no te vendría nada mal este genial control, Html Renderer:

saludos!

 


« Última modificación: 7 Marzo 2016, 22:09 pm por Eleкtro » En línea

Slava_TZD
Wiki

Desconectado Desconectado

Mensajes: 1.466

♪ [8675309] ♪


Ver Perfil WWW
Re: Agregar palabras reservadas a un richtextbox
« Respuesta #2 en: 7 Marzo 2016, 22:09 pm »

Si lo quieres hacer por ti mismo tienes que hacer una selección y luego utilizar SelectionColor por cada palabra. Puedes hacer un metodo con un switch o ifs que devuelvan el color dependiendo de la palabra no se si me explico.
En línea


The fact is, even if you were to stop bombing us, imprisoning us, torturing us, vilifying us, and usurping our lands, we would continue to hate you because our primary reason for hating you will not cease to exist until you embrace Islam.
nolasco281


Desconectado Desconectado

Mensajes: 319


Ver Perfil
Re: Agregar palabras reservadas a un richtextbox
« Respuesta #3 en: 8 Marzo 2016, 02:46 am »

Muchas gracias por la ayuda a los dos ya estoy viendo ejemplos y probando las paginas que me proporciono Eleкtro.

Gracias de nuevo saludos.
En línea

Lo que se puede imaginar... se puede programar.
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Agregar palabras reservadas a un richtextbox
« Respuesta #4 en: 8 Marzo 2016, 12:47 pm »

Una cosa que ayer no recordé para comentarte, la forma mas eficiente de llevar a cabo la colorización de la sintaxis sería utilizando el motor Roslyn de Microsoft (puedes encontrar las librerías en GitHub, y la SDK de Visual Studio), es el mismo mecanimsmo que usa visual Studio para ello, pero no hace relativamente mucho que es open-source y no existe demasiada documentación al respecto, aunque si que hay algunos buenos ejemplos, pero es un sistema muy tedioso de pulir para implementarlo en una app con este tipo de finalidad que le quieres dar.

Otra cosa con respecto a lo que ha sugerido @Slava, un Richtextbox es un control muy pesado, y si a eso le sumamos metodologías de iteración del texto cada vez que el usuario pulse una tecla (o con un Timer, me da igual), en términos de rendmiento el resultado será una completa catástrofe irritante. Si vas a intentarlo así, entonces debes interactuar lo más mínimo con el texto/control, lo que hay que hacer es llevar a cabo una evaluación de la palabra actual por separado, en un tipo personalizado, con el texto actual, su longitud actual, si coincide con algún keyword conocido o no, etc, y mientras tanto ignorar el texto del control y todo lo demás mientras el usuario no borre o añada ninguna letra. Espero haberme explicado más o menos bien!



Bueno, al final me he animado a construir un estilo para VisualBasic.Net en Scintilla, voy a compartirlo contigo :)

No está del todo completo y no es perfecto, existen unos pequeños conflictos ...esto último debido a las limitaciones del control, pero asumiendo esos pequeños conflictos creo que podemos dar este estilo como un estilo válido y bonito, que me lo he currado, coño! xD.

El diseño del editor de Visual Studio es el que más me gusta, así que no he querido reinventar la rueda y lo he coloreado de forma similar...

Unas imágenes del resultado:





Código
  1.    ''' ----------------------------------------------------------------------------------------------------
  2.    ''' <summary>
  3.    ''' Sets a VisualBasic.Net dark lexer style on the specified <see cref="Scintilla"/> editor.
  4.    ''' </summary>
  5.    ''' ----------------------------------------------------------------------------------------------------
  6.    ''' <param name="editor">
  7.    ''' The source <see cref="Scintilla"/> editor.
  8.    ''' </param>
  9.    ''' ----------------------------------------------------------------------------------------------------
  10.    Public Shared Sub SetVbNetDarkStyle(ByVal editor As Scintilla)
  11.  
  12.        Dim backColor As Color = Color.FromArgb(255, 30, 30, 30)
  13.        Dim selectionColor As Color = Color.FromArgb(255, 38, 79, 120)
  14.  
  15.        Dim keywords As String =
  16. <a>
  17. release
  18. addhandler
  19. addressof
  20. aggregate
  21. alias
  22. and
  23. andalso
  24. ansi
  25. as
  26. assembly
  27. auto
  28. binary
  29. boolean
  30. byref
  31. byte
  32. byval
  33. call
  34. case
  35. catch
  36. cbool
  37. cbyte
  38. cchar
  39. cdate
  40. cdbl
  41. cdec
  42. char
  43. cint
  44. class
  45. clng
  46. cobj
  47. compare
  48. const
  49. continue
  50. csbyte
  51. cshort
  52. csng
  53. cstr
  54. ctype
  55. cuint
  56. culng
  57. cushort
  58. custom
  59. date
  60. decimal
  61. declare
  62. default
  63. delegate
  64. dim
  65. directcast
  66. distinct
  67. do
  68. double
  69. each
  70. else
  71. elseif
  72. end
  73. endif
  74. enum
  75. equals
  76. erase
  77. error
  78. event
  79. exit
  80. explicit
  81. false
  82. finally
  83. for
  84. friend
  85. from
  86. function
  87. get
  88. gettype
  89. getxmlnamespace
  90. global
  91. gosub
  92. goto
  93. group
  94. handles
  95. if
  96. implements
  97. imports
  98. in
  99. inherits
  100. integer
  101. interface
  102. into
  103. is
  104. isfalse
  105. isnot
  106. istrue
  107. join
  108. key
  109. let
  110. lib
  111. like
  112. long
  113. loop
  114. me
  115. mid
  116. mod
  117. module
  118. mustinherit
  119. mustoverride
  120. my
  121. mybase
  122. myclass
  123. namespace
  124. narrowing
  125. new
  126. next
  127. not
  128. nothing
  129. notinheritable
  130. notoverridable
  131. object
  132. of
  133. off
  134. on
  135. operator
  136. option
  137. optional
  138. or
  139. order
  140. orelse
  141. overloads
  142. overridable
  143. overrides
  144. paramarray
  145. partial
  146. preserve
  147. private
  148. property
  149. protected
  150. public
  151. raiseevent
  152. readonly
  153. redim
  154. rem
  155. removehandler
  156. resume
  157. return
  158. sbyte
  159. select
  160. set
  161. shadows
  162. shared
  163. short
  164. single
  165. skip
  166. static
  167. step
  168. stop
  169. strict
  170. string
  171. structure
  172. sub
  173. synclock
  174. take
  175. text
  176. then
  177. throw
  178. to
  179. true
  180. try
  181. trycast
  182. typeof
  183. uinteger
  184. ulong
  185. unicode
  186. until
  187. ushort
  188. using
  189. variant
  190. wend
  191. when
  192. where
  193. while
  194. widening
  195. with
  196. withevents
  197. writeonly
  198. xor
  199. </a>.Value
  200.  
  201.        Dim typenames As String =
  202. <a>
  203. array
  204. backgroundworker
  205. bitmap
  206. button
  207. checkbox
  208. checkedlistbox
  209. colordialog
  210. combobox
  211. component
  212. contextmenustrip
  213. control
  214. datagridview
  215. dataset
  216. datetime
  217. datetimepicker
  218. directorysearcher
  219. errorprovider
  220. eventlog
  221. exception
  222. fileinfo
  223. filesystemwatcher
  224. flowlayoutpanel
  225. form
  226. graphics
  227. groupbox
  228. helpprovider
  229. hscrollbar
  230. iappdomainsetup
  231. iasyncresult
  232. ibindablecomponent
  233. ibuttoncontrol
  234. icloneable
  235. icollectdatta
  236. icollection
  237. icolumnmapping
  238. icolumnmappingcollection
  239. icommandexecutor
  240. icomparable
  241. icomparer
  242. icomponent
  243. icomponenteditorpagesite
  244. icontainercontrol
  245. iconvertible
  246. icurrencymanagerprovider
  247. icustomformatter
  248. idataadapter
  249. idatagridcolumnstyleeditingnotificationservice
  250. idatagrideditingservice
  251. idatagridvieweditingcell
  252. idatagridvieweditingcontrol
  253. idataobject
  254. idataparameter
  255. idataparametercollection
  256. idatareader
  257. idatarecord
  258. idbcommand
  259. idbconnection
  260. idbdataadapter
  261. idbdataparameter
  262. idbtransaction
  263. idevicecontext
  264. idictionary
  265. idictionaryenumerator
  266. idisposable
  267. idroptarget
  268. ienumerable
  269. ienumerator
  270. iequalitycomparer
  271. iequatable
  272. ifeaturesupport
  273. ifilereaderservice
  274. iformatprovider
  275. iformattable
  276. iformatter
  277. igroupping
  278. ihashcodeprovider
  279. ilist
  280. ilookup
  281. image
  282. imagelist
  283. imessagefilter
  284. inotifypropertychanged
  285. int16
  286. int32
  287. int64
  288. iobservable
  289. iobserver
  290. iorderedenumerable
  291. iorderedqueryable
  292. iqueryable
  293. iqueryprovider
  294. iserializable
  295. iserviceprovider
  296. iset
  297. istructuralcomparable
  298. istructuralequatable
  299. itablemapping
  300. itablemappingcollection
  301. iwin32window
  302. iwindowtarget
  303. label
  304. linklabel
  305. list
  306. listbox
  307. listview
  308. maskedtextbox
  309. menustrip
  310. messagequeue
  311. monthcalendar
  312. nativewindow
  313. notifyicon
  314. numericupdown
  315. openfiledialog
  316. panel
  317. pen
  318. performancecounter
  319. picturebox
  320. point
  321. pointf
  322. printdialog
  323. printdocument
  324. process
  325. progressbar
  326. propertygrid
  327. radiobutton
  328. readonlycollection
  329. rectangle
  330. rectanglef
  331. regex
  332. richtextbox
  333. savefiledialog
  334. serialport
  335. servicecontroller
  336. size
  337. sizef
  338. solidbrush
  339. splitcontainer
  340. statusstrip
  341. system
  342. tabcontrol
  343. tablelayoutpanel
  344. textbox
  345. timer
  346. toolstrip
  347. toolstripcontainer
  348. tooltip
  349. trackbar
  350. type
  351. uint16
  352. uint32
  353. uint64
  354. vscrollbar
  355. webbrowser
  356. </a>.Value
  357.  
  358.        Dim literals As String =
  359. <a>
  360. !
  361. #
  362. %
  363. @
  364. &amp;
  365. i
  366. d
  367. f
  368. l
  369. r
  370. s
  371. ui
  372. ul
  373. us
  374. </a>.Value
  375.  
  376.        Dim other As String = "_" ' line-break.
  377.  
  378.        ' Reset the styles.
  379.        editor.StyleResetDefault()
  380.        editor.StyleClearAll()
  381.        ' editor.Styles(Style.[Default]).Font = "Consolas"
  382.        ' editor.Styles(Style.[Default]).Size = 10
  383.  
  384.        ' Set the Vb.Net lexer.
  385.        editor.Lexer = Lexer.Vb
  386.  
  387.        ' Set folding properties.
  388.        With editor
  389.            .SetProperty("fold", "1")
  390.            .SetProperty("fold.compact", "1")
  391.            .SetProperty("fold.html", "1")
  392.        End With
  393.  
  394.        ' Set the margin for fold markers.
  395.        With editor
  396.            .Margins(2).Type = MarginType.Symbol
  397.            .Margins(2).Mask = Marker.MaskFolders
  398.            .Margins(2).Sensitive = True
  399.            .Margins(2).Width = 20
  400.        End With
  401.  
  402.        ' Reset folder markers.
  403.        For i As Integer = Marker.FolderEnd To Marker.FolderOpen
  404.            editor.Markers(i).SetForeColor(SystemColors.ControlLightLight)
  405.            editor.Markers(i).SetBackColor(SystemColors.ControlDark)
  406.        Next
  407.  
  408.        ' Set the style of the folder markers.
  409.        With editor
  410.            .Markers(Marker.Folder).Symbol = MarkerSymbol.BoxPlus
  411.            .Markers(Marker.Folder).SetBackColor(SystemColors.ControlText)
  412.            .Markers(Marker.FolderOpen).Symbol = MarkerSymbol.BoxMinus
  413.            .Markers(Marker.FolderEnd).Symbol = MarkerSymbol.BoxPlusConnected
  414.            .Markers(Marker.FolderEnd).SetBackColor(SystemColors.ControlText)
  415.            .Markers(Marker.FolderMidTail).Symbol = MarkerSymbol.TCorner
  416.            .Markers(Marker.FolderOpenMid).Symbol = MarkerSymbol.BoxMinusConnected
  417.            .Markers(Marker.FolderSub).Symbol = MarkerSymbol.VLine
  418.            .Markers(Marker.FolderTail).Symbol = MarkerSymbol.LCorner
  419.        End With
  420.  
  421.        ' Enable automatic folding
  422.        editor.AutomaticFold = (AutomaticFold.Show Or AutomaticFold.Click Or AutomaticFold.Change)
  423.  
  424.        ' Disable whitespaces visibility.
  425.        editor.ViewWhitespace = WhitespaceMode.Invisible
  426.  
  427.        ' Set the selection color.
  428.        editor.SetSelectionBackColor(True, selectionColor)
  429.  
  430.        ' Set the style of the Vb.Net language.
  431.        With editor
  432.            .Styles(Style.Default).BackColor = backColor
  433.  
  434.            .Styles(Style.Vb.Asm).BackColor = backColor
  435.            .Styles(Style.Vb.Asm).ForeColor = Color.FromArgb(255, 181, 206, 168)
  436.            .Styles(Style.Vb.Asm).Bold = True
  437.            .Styles(Style.Vb.Asm).Italic = False
  438.            .Styles(Style.Vb.Asm).Underline = False
  439.  
  440.            .Styles(Style.Vb.BinNumber).BackColor = backColor
  441.            .Styles(Style.Vb.BinNumber).ForeColor = Color.FromArgb(255, 181, 206, 168)
  442.            .Styles(Style.Vb.BinNumber).Bold = False
  443.            .Styles(Style.Vb.BinNumber).Italic = False
  444.            .Styles(Style.Vb.BinNumber).Underline = False
  445.  
  446.            .Styles(Style.Vb.Comment).BackColor = backColor
  447.            .Styles(Style.Vb.Comment).ForeColor = Color.FromArgb(255, 87, 159, 56)
  448.            .Styles(Style.Vb.Comment).Bold = False
  449.            .Styles(Style.Vb.Comment).Italic = False
  450.            .Styles(Style.Vb.Comment).Underline = False
  451.  
  452.            .Styles(Style.Vb.CommentBlock).BackColor = backColor
  453.            .Styles(Style.Vb.CommentBlock).ForeColor = Color.FromArgb(255, 87, 159, 56)
  454.            .Styles(Style.Vb.CommentBlock).Bold = False
  455.            .Styles(Style.Vb.CommentBlock).Italic = False
  456.            .Styles(Style.Vb.CommentBlock).Underline = False
  457.  
  458.            .Styles(Style.Vb.Constant).BackColor = backColor
  459.            .Styles(Style.Vb.Constant).ForeColor = Color.MediumOrchid
  460.            .Styles(Style.Vb.Constant).Bold = False
  461.            .Styles(Style.Vb.Constant).Italic = False
  462.            .Styles(Style.Vb.Constant).Underline = False
  463.  
  464.            .Styles(Style.Vb.Date).BackColor = backColor
  465.            .Styles(Style.Vb.Date).ForeColor = Color.MediumOrchid
  466.            .Styles(Style.Vb.Date).Bold = False
  467.            .Styles(Style.Vb.Date).Italic = False
  468.            .Styles(Style.Vb.Date).Underline = False
  469.  
  470.            .Styles(Style.Vb.Default).BackColor = backColor
  471.            .Styles(Style.Vb.Default).ForeColor = Color.LightGray
  472.            .Styles(Style.Vb.Default).Bold = False
  473.            .Styles(Style.Vb.Default).Italic = False
  474.            .Styles(Style.Vb.Default).Underline = False
  475.  
  476.            .Styles(Style.Vb.DocBlock).BackColor = backColor
  477.            .Styles(Style.Vb.DocBlock).ForeColor = Color.FromArgb(255, 87, 159, 56)
  478.            .Styles(Style.Vb.DocBlock).Bold = False
  479.            .Styles(Style.Vb.DocBlock).Italic = False
  480.            .Styles(Style.Vb.DocBlock).Underline = False
  481.  
  482.            .Styles(Style.Vb.DocKeyword).BackColor = backColor
  483.            .Styles(Style.Vb.DocKeyword).ForeColor = Color.FromArgb(255, 100, 150, 215)
  484.            .Styles(Style.Vb.DocKeyword).Bold = False
  485.            .Styles(Style.Vb.DocKeyword).Italic = False
  486.            .Styles(Style.Vb.DocKeyword).Underline = False
  487.  
  488.            .Styles(Style.Vb.DocLine).BackColor = backColor
  489.            .Styles(Style.Vb.DocLine).ForeColor = Color.FromArgb(255, 87, 159, 56)
  490.            .Styles(Style.Vb.DocLine).Bold = False
  491.            .Styles(Style.Vb.DocLine).Italic = False
  492.            .Styles(Style.Vb.DocLine).Underline = False
  493.  
  494.            .Styles(Style.Vb.Error).BackColor = backColor
  495.            .Styles(Style.Vb.Error).ForeColor = Color.IndianRed
  496.            .Styles(Style.Vb.Error).Bold = True
  497.            .Styles(Style.Vb.Error).Italic = False
  498.            .Styles(Style.Vb.Error).Underline = False
  499.  
  500.            .Styles(Style.Vb.HexNumber).BackColor = backColor
  501.            .Styles(Style.Vb.HexNumber).ForeColor = Color.FromArgb(255, 181, 206, 168)
  502.            .Styles(Style.Vb.HexNumber).Bold = False
  503.            .Styles(Style.Vb.HexNumber).Italic = False
  504.            .Styles(Style.Vb.HexNumber).Underline = False
  505.  
  506.            .Styles(Style.Vb.Identifier).BackColor = backColor
  507.            .Styles(Style.Vb.Identifier).ForeColor = Color.Gainsboro
  508.            .Styles(Style.Vb.Identifier).Bold = False
  509.            .Styles(Style.Vb.Identifier).Italic = False
  510.            .Styles(Style.Vb.Identifier).Underline = False
  511.  
  512.            .Styles(Style.Vb.Keyword).BackColor = backColor
  513.            .Styles(Style.Vb.Keyword).ForeColor = Color.FromArgb(255, 100, 150, 215)
  514.            .Styles(Style.Vb.Keyword).Bold = False
  515.            .Styles(Style.Vb.Keyword).Italic = False
  516.            .Styles(Style.Vb.Keyword).Underline = False
  517.  
  518.            .Styles(Style.Vb.Keyword2).BackColor = backColor
  519.            .Styles(Style.Vb.Keyword2).ForeColor = Color.FromArgb(255, 62, 201, 174)
  520.            .Styles(Style.Vb.Keyword2).Bold = False
  521.            .Styles(Style.Vb.Keyword2).Italic = False
  522.            .Styles(Style.Vb.Keyword2).Underline = False
  523.  
  524.            .Styles(Style.Vb.Keyword3).BackColor = backColor
  525.            .Styles(Style.Vb.Keyword3).ForeColor = Color.FromArgb(255, 181, 206, 168)
  526.            .Styles(Style.Vb.Keyword3).Bold = False
  527.            .Styles(Style.Vb.Keyword3).Italic = False
  528.            .Styles(Style.Vb.Keyword3).Underline = False
  529.  
  530.            .Styles(Style.Vb.Keyword4).BackColor = backColor
  531.            .Styles(Style.Vb.Keyword4).ForeColor = Color.IndianRed
  532.            .Styles(Style.Vb.Keyword4).Bold = False
  533.            .Styles(Style.Vb.Keyword4).Italic = False
  534.            .Styles(Style.Vb.Keyword4).Underline = False
  535.  
  536.            .Styles(Style.Vb.Label).BackColor = backColor
  537.            .Styles(Style.Vb.Label).ForeColor = Color.FromArgb(255, 100, 150, 215)
  538.            .Styles(Style.Vb.Label).Bold = False
  539.            .Styles(Style.Vb.Label).Italic = False
  540.            .Styles(Style.Vb.Label).Underline = False
  541.  
  542.            .Styles(Style.Vb.Number).BackColor = backColor
  543.            .Styles(Style.Vb.Number).ForeColor = Color.FromArgb(255, 181, 206, 168)
  544.            .Styles(Style.Vb.Number).Bold = False
  545.            .Styles(Style.Vb.Number).Italic = False
  546.            .Styles(Style.Vb.Number).Underline = False
  547.  
  548.            .Styles(Style.Vb.Operator).BackColor = backColor
  549.            ' .Styles(Style.Vb.Operator).ForeColor = Color.DarkKhaki
  550.            ' .Styles(Style.Vb.Operator).ForeColor = Color.DarkCyan
  551.            ' .Styles(Style.Vb.Operator).ForeColor = Color.Honeydew
  552.            ' .Styles(Style.Vb.Operator).ForeColor = Color.LightSteelBlue
  553.            .Styles(Style.Vb.Operator).ForeColor = Color.LightSlateGray
  554.            .Styles(Style.Vb.Operator).Bold = True
  555.            .Styles(Style.Vb.Operator).Italic = False
  556.            .Styles(Style.Vb.Operator).Underline = False
  557.  
  558.            .Styles(Style.Vb.Preprocessor).BackColor = backColor
  559.            ' .Styles(Style.Vb.Preprocessor).ForeColor = Color.HotPink
  560.            .Styles(Style.Vb.Preprocessor).ForeColor = Color.LightSlateGray
  561.            .Styles(Style.Vb.Preprocessor).Bold = False
  562.            .Styles(Style.Vb.Preprocessor).Italic = False
  563.            .Styles(Style.Vb.Preprocessor).Underline = False
  564.  
  565.            .Styles(Style.Vb.String).BackColor = backColor
  566.            .Styles(Style.Vb.String).ForeColor = Color.FromArgb(255, 214, 157, 133)
  567.            .Styles(Style.Vb.String).Bold = False
  568.            .Styles(Style.Vb.String).Italic = False
  569.            .Styles(Style.Vb.String).Underline = False
  570.  
  571.            .Styles(Style.Vb.StringEol).BackColor = backColor
  572.            .Styles(Style.Vb.StringEol).ForeColor = Color.Gainsboro
  573.            .Styles(Style.Vb.StringEol).FillLine = True
  574.            .Styles(Style.Vb.StringEol).Bold = False
  575.            .Styles(Style.Vb.StringEol).Italic = False
  576.            .Styles(Style.Vb.StringEol).Underline = False
  577.  
  578.        End With
  579.  
  580.        ' Set the Vb.Net keywords.
  581.        editor.SetKeywords(0, keywords)
  582.        editor.SetKeywords(1, typenames)
  583.        editor.SetKeywords(2, literals)
  584.        editor.SetKeywords(3, other)
  585.  
  586.    End Sub
  587.  

Código
  1.    ''' ----------------------------------------------------------------------------------------------------
  2.    ''' <summary>
  3.    ''' Sets a VisualBasic.Net light lexer style on the specified <see cref="Scintilla"/> editor.
  4.    ''' </summary>
  5.    ''' ----------------------------------------------------------------------------------------------------
  6.    ''' <param name="editor">
  7.    ''' The source <see cref="Scintilla"/> editor.
  8.    ''' </param>
  9.    ''' ----------------------------------------------------------------------------------------------------
  10.    Public Shared Sub SetVbNetLightStyle(ByVal editor As Scintilla)
  11.  
  12.        Dim backColor As Color = Color.WhiteSmoke
  13.        Dim selectionColor As Color = Color.FromArgb(255, 38, 79, 120)
  14.  
  15.        Dim keywords As String =
  16. <a>
  17. release
  18. addhandler
  19. addressof
  20. aggregate
  21. alias
  22. and
  23. andalso
  24. ansi
  25. as
  26. assembly
  27. auto
  28. binary
  29. boolean
  30. byref
  31. byte
  32. byval
  33. call
  34. case
  35. catch
  36. cbool
  37. cbyte
  38. cchar
  39. cdate
  40. cdbl
  41. cdec
  42. char
  43. cint
  44. class
  45. clng
  46. cobj
  47. compare
  48. const
  49. continue
  50. csbyte
  51. cshort
  52. csng
  53. cstr
  54. ctype
  55. cuint
  56. culng
  57. cushort
  58. custom
  59. date
  60. decimal
  61. declare
  62. default
  63. delegate
  64. dim
  65. directcast
  66. distinct
  67. do
  68. double
  69. each
  70. else
  71. elseif
  72. end
  73. endif
  74. enum
  75. equals
  76. erase
  77. error
  78. event
  79. exit
  80. explicit
  81. false
  82. finally
  83. for
  84. friend
  85. from
  86. function
  87. get
  88. gettype
  89. getxmlnamespace
  90. global
  91. gosub
  92. goto
  93. group
  94. handles
  95. if
  96. implements
  97. imports
  98. in
  99. inherits
  100. integer
  101. interface
  102. into
  103. is
  104. isfalse
  105. isnot
  106. istrue
  107. join
  108. key
  109. let
  110. lib
  111. like
  112. long
  113. loop
  114. me
  115. mid
  116. mod
  117. module
  118. mustinherit
  119. mustoverride
  120. my
  121. mybase
  122. myclass
  123. namespace
  124. narrowing
  125. new
  126. next
  127. not
  128. nothing
  129. notinheritable
  130. notoverridable
  131. object
  132. of
  133. off
  134. on
  135. operator
  136. option
  137. optional
  138. or
  139. order
  140. orelse
  141. overloads
  142. overridable
  143. overrides
  144. paramarray
  145. partial
  146. preserve
  147. private
  148. property
  149. protected
  150. public
  151. raiseevent
  152. readonly
  153. redim
  154. rem
  155. removehandler
  156. resume
  157. return
  158. sbyte
  159. select
  160. set
  161. shadows
  162. shared
  163. short
  164. single
  165. skip
  166. static
  167. step
  168. stop
  169. strict
  170. string
  171. structure
  172. sub
  173. synclock
  174. take
  175. text
  176. then
  177. throw
  178. to
  179. true
  180. try
  181. trycast
  182. typeof
  183. uinteger
  184. ulong
  185. unicode
  186. until
  187. ushort
  188. using
  189. variant
  190. wend
  191. when
  192. where
  193. while
  194. widening
  195. with
  196. withevents
  197. writeonly
  198. xor
  199. </a>.Value
  200.  
  201.        Dim typenames As String =
  202. <a>
  203. array
  204. backgroundworker
  205. bitmap
  206. button
  207. checkbox
  208. checkedlistbox
  209. colordialog
  210. combobox
  211. component
  212. contextmenustrip
  213. control
  214. datagridview
  215. dataset
  216. datetime
  217. datetimepicker
  218. directorysearcher
  219. errorprovider
  220. eventlog
  221. exception
  222. fileinfo
  223. filesystemwatcher
  224. flowlayoutpanel
  225. form
  226. graphics
  227. groupbox
  228. helpprovider
  229. hscrollbar
  230. iappdomainsetup
  231. iasyncresult
  232. ibindablecomponent
  233. ibuttoncontrol
  234. icloneable
  235. icollectdatta
  236. icollection
  237. icolumnmapping
  238. icolumnmappingcollection
  239. icommandexecutor
  240. icomparable
  241. icomparer
  242. icomponent
  243. icomponenteditorpagesite
  244. icontainercontrol
  245. iconvertible
  246. icurrencymanagerprovider
  247. icustomformatter
  248. idataadapter
  249. idatagridcolumnstyleeditingnotificationservice
  250. idatagrideditingservice
  251. idatagridvieweditingcell
  252. idatagridvieweditingcontrol
  253. idataobject
  254. idataparameter
  255. idataparametercollection
  256. idatareader
  257. idatarecord
  258. idbcommand
  259. idbconnection
  260. idbdataadapter
  261. idbdataparameter
  262. idbtransaction
  263. idevicecontext
  264. idictionary
  265. idictionaryenumerator
  266. idisposable
  267. idroptarget
  268. ienumerable
  269. ienumerator
  270. iequalitycomparer
  271. iequatable
  272. ifeaturesupport
  273. ifilereaderservice
  274. iformatprovider
  275. iformattable
  276. iformatter
  277. igroupping
  278. ihashcodeprovider
  279. ilist
  280. ilookup
  281. image
  282. imagelist
  283. imessagefilter
  284. inotifypropertychanged
  285. int16
  286. int32
  287. int64
  288. iobservable
  289. iobserver
  290. iorderedenumerable
  291. iorderedqueryable
  292. iqueryable
  293. iqueryprovider
  294. iserializable
  295. iserviceprovider
  296. iset
  297. istructuralcomparable
  298. istructuralequatable
  299. itablemapping
  300. itablemappingcollection
  301. iwin32window
  302. iwindowtarget
  303. label
  304. linklabel
  305. list
  306. listbox
  307. listview
  308. maskedtextbox
  309. menustrip
  310. messagequeue
  311. monthcalendar
  312. nativewindow
  313. notifyicon
  314. numericupdown
  315. openfiledialog
  316. panel
  317. pen
  318. performancecounter
  319. picturebox
  320. point
  321. pointf
  322. printdialog
  323. printdocument
  324. process
  325. progressbar
  326. propertygrid
  327. radiobutton
  328. readonlycollection
  329. rectangle
  330. rectanglef
  331. regex
  332. richtextbox
  333. savefiledialog
  334. serialport
  335. servicecontroller
  336. size
  337. sizef
  338. solidbrush
  339. splitcontainer
  340. statusstrip
  341. system
  342. tabcontrol
  343. tablelayoutpanel
  344. textbox
  345. timer
  346. toolstrip
  347. toolstripcontainer
  348. tooltip
  349. trackbar
  350. type
  351. uint16
  352. uint32
  353. uint64
  354. vscrollbar
  355. webbrowser
  356. </a>.Value
  357.  
  358.        Dim literals As String =
  359. <a>
  360. !
  361. #
  362. %
  363. @
  364. &amp;
  365. i
  366. d
  367. f
  368. l
  369. r
  370. s
  371. ui
  372. ul
  373. us
  374. </a>.Value
  375.  
  376.        Dim other As String = "_" ' line-break.
  377.  
  378.        ' Reset the styles.
  379.        editor.StyleResetDefault()
  380.        editor.StyleClearAll()
  381.        ' editor.Styles(Style.[Default]).Font = "Consolas"
  382.        ' editor.Styles(Style.[Default]).Size = 10
  383.  
  384.        ' Set the Vb.Net lexer.
  385.        editor.Lexer = Lexer.Vb
  386.  
  387.        ' Set folding properties.
  388.        With editor
  389.            .SetProperty("fold", "1")
  390.            .SetProperty("fold.compact", "1")
  391.            .SetProperty("fold.html", "1")
  392.        End With
  393.  
  394.        ' Set the margin for fold markers.
  395.        With editor
  396.            .Margins(2).Type = MarginType.Symbol
  397.            .Margins(2).Mask = Marker.MaskFolders
  398.            .Margins(2).Sensitive = True
  399.            .Margins(2).Width = 20
  400.        End With
  401.  
  402.        ' Reset folder markers.
  403.        For i As Integer = Marker.FolderEnd To Marker.FolderOpen
  404.            editor.Markers(i).SetForeColor(SystemColors.ControlLightLight)
  405.            editor.Markers(i).SetBackColor(SystemColors.ControlDark)
  406.        Next
  407.  
  408.        ' Set the style of the folder markers.
  409.        With editor
  410.            .Markers(Marker.Folder).Symbol = MarkerSymbol.BoxPlus
  411.            .Markers(Marker.Folder).SetBackColor(SystemColors.ControlText)
  412.            .Markers(Marker.FolderOpen).Symbol = MarkerSymbol.BoxMinus
  413.            .Markers(Marker.FolderEnd).Symbol = MarkerSymbol.BoxPlusConnected
  414.            .Markers(Marker.FolderEnd).SetBackColor(SystemColors.ControlText)
  415.            .Markers(Marker.FolderMidTail).Symbol = MarkerSymbol.TCorner
  416.            .Markers(Marker.FolderOpenMid).Symbol = MarkerSymbol.BoxMinusConnected
  417.            .Markers(Marker.FolderSub).Symbol = MarkerSymbol.VLine
  418.            .Markers(Marker.FolderTail).Symbol = MarkerSymbol.LCorner
  419.        End With
  420.  
  421.        ' Enable automatic folding
  422.        editor.AutomaticFold = (AutomaticFold.Show Or AutomaticFold.Click Or AutomaticFold.Change)
  423.  
  424.        ' Disable whitespaces visibility.
  425.        editor.ViewWhitespace = WhitespaceMode.Invisible
  426.  
  427.        ' Set the selection color.
  428.        '  editor.SetSelectionBackColor(True, selectionColor)
  429.  
  430.        ' Set the style of the Vb.Net language.
  431.        With editor
  432.            .Styles(Style.Default).BackColor = backColor
  433.  
  434.            .Styles(Style.Vb.Asm).BackColor = backColor
  435.            .Styles(Style.Vb.Asm).ForeColor = Color.OrangeRed
  436.            .Styles(Style.Vb.Asm).Bold = True
  437.            .Styles(Style.Vb.Asm).Italic = False
  438.            .Styles(Style.Vb.Asm).Underline = False
  439.  
  440.            .Styles(Style.Vb.BinNumber).BackColor = backColor
  441.            .Styles(Style.Vb.BinNumber).ForeColor = Color.OrangeRed
  442.            .Styles(Style.Vb.BinNumber).Bold = False
  443.            .Styles(Style.Vb.BinNumber).Italic = False
  444.            .Styles(Style.Vb.BinNumber).Underline = False
  445.  
  446.            .Styles(Style.Vb.Comment).BackColor = backColor
  447.            .Styles(Style.Vb.Comment).ForeColor = Color.Green
  448.            .Styles(Style.Vb.Comment).Bold = False
  449.            .Styles(Style.Vb.Comment).Italic = False
  450.            .Styles(Style.Vb.Comment).Underline = False
  451.  
  452.            .Styles(Style.Vb.CommentBlock).BackColor = backColor
  453.            .Styles(Style.Vb.CommentBlock).ForeColor = Color.Green
  454.            .Styles(Style.Vb.CommentBlock).Bold = False
  455.            .Styles(Style.Vb.CommentBlock).Italic = False
  456.            .Styles(Style.Vb.CommentBlock).Underline = False
  457.  
  458.            .Styles(Style.Vb.Constant).BackColor = backColor
  459.            .Styles(Style.Vb.Constant).ForeColor = Color.DarkMagenta
  460.            .Styles(Style.Vb.Constant).Bold = False
  461.            .Styles(Style.Vb.Constant).Italic = False
  462.            .Styles(Style.Vb.Constant).Underline = False
  463.  
  464.            .Styles(Style.Vb.Date).BackColor = backColor
  465.            .Styles(Style.Vb.Date).ForeColor = Color.DarkMagenta
  466.            .Styles(Style.Vb.Date).Bold = False
  467.            .Styles(Style.Vb.Date).Italic = False
  468.            .Styles(Style.Vb.Date).Underline = False
  469.  
  470.            .Styles(Style.Vb.Default).BackColor = backColor
  471.            .Styles(Style.Vb.Default).ForeColor = Color.Black
  472.            .Styles(Style.Vb.Default).Bold = False
  473.            .Styles(Style.Vb.Default).Italic = False
  474.            .Styles(Style.Vb.Default).Underline = False
  475.  
  476.            .Styles(Style.Vb.DocBlock).BackColor = backColor
  477.            .Styles(Style.Vb.DocBlock).ForeColor = Color.Green
  478.            .Styles(Style.Vb.DocBlock).Bold = False
  479.            .Styles(Style.Vb.DocBlock).Italic = False
  480.            .Styles(Style.Vb.DocBlock).Underline = False
  481.  
  482.            .Styles(Style.Vb.DocKeyword).BackColor = backColor
  483.            .Styles(Style.Vb.DocKeyword).ForeColor = Color.FromArgb(255, 64, 47, 241)
  484.            .Styles(Style.Vb.DocKeyword).Bold = False
  485.            .Styles(Style.Vb.DocKeyword).Italic = False
  486.            .Styles(Style.Vb.DocKeyword).Underline = False
  487.  
  488.            .Styles(Style.Vb.DocLine).BackColor = backColor
  489.            .Styles(Style.Vb.DocLine).ForeColor = Color.Green
  490.            .Styles(Style.Vb.DocLine).Bold = False
  491.            .Styles(Style.Vb.DocLine).Italic = False
  492.            .Styles(Style.Vb.DocLine).Underline = False
  493.  
  494.            .Styles(Style.Vb.Error).BackColor = backColor
  495.            .Styles(Style.Vb.Error).ForeColor = Color.OrangeRed
  496.            .Styles(Style.Vb.Error).Bold = True
  497.            .Styles(Style.Vb.Error).Italic = False
  498.            .Styles(Style.Vb.Error).Underline = False
  499.  
  500.            .Styles(Style.Vb.HexNumber).BackColor = backColor
  501.            .Styles(Style.Vb.HexNumber).ForeColor = Color.OrangeRed
  502.            .Styles(Style.Vb.HexNumber).Bold = False
  503.            .Styles(Style.Vb.HexNumber).Italic = False
  504.            .Styles(Style.Vb.HexNumber).Underline = False
  505.  
  506.            .Styles(Style.Vb.Identifier).BackColor = backColor
  507.            .Styles(Style.Vb.Identifier).ForeColor = Color.Black
  508.            .Styles(Style.Vb.Identifier).Bold = False
  509.            .Styles(Style.Vb.Identifier).Italic = False
  510.            .Styles(Style.Vb.Identifier).Underline = False
  511.  
  512.            .Styles(Style.Vb.Keyword).BackColor = backColor
  513.            .Styles(Style.Vb.Keyword).ForeColor = Color.FromArgb(255, 72, 64, 213)
  514.            .Styles(Style.Vb.Keyword).Bold = False
  515.            .Styles(Style.Vb.Keyword).Italic = False
  516.            .Styles(Style.Vb.Keyword).Underline = False
  517.  
  518.            .Styles(Style.Vb.Keyword2).BackColor = backColor
  519.            .Styles(Style.Vb.Keyword2).ForeColor = Color.DarkCyan
  520.            .Styles(Style.Vb.Keyword2).Bold = False
  521.            .Styles(Style.Vb.Keyword2).Italic = False
  522.            .Styles(Style.Vb.Keyword2).Underline = False
  523.  
  524.            .Styles(Style.Vb.Keyword3).BackColor = backColor
  525.            .Styles(Style.Vb.Keyword3).ForeColor = Color.OrangeRed
  526.            .Styles(Style.Vb.Keyword3).Bold = False
  527.            .Styles(Style.Vb.Keyword3).Italic = False
  528.            .Styles(Style.Vb.Keyword3).Underline = False
  529.  
  530.            .Styles(Style.Vb.Keyword4).BackColor = backColor
  531.            .Styles(Style.Vb.Keyword4).ForeColor = Color.DarkRed
  532.            .Styles(Style.Vb.Keyword4).Bold = False
  533.            .Styles(Style.Vb.Keyword4).Italic = False
  534.            .Styles(Style.Vb.Keyword4).Underline = False
  535.  
  536.            .Styles(Style.Vb.Label).BackColor = backColor
  537.            .Styles(Style.Vb.Label).ForeColor = Color.FromArgb(255, 72, 64, 213)
  538.            .Styles(Style.Vb.Label).Bold = False
  539.            .Styles(Style.Vb.Label).Italic = False
  540.            .Styles(Style.Vb.Label).Underline = False
  541.  
  542.            .Styles(Style.Vb.Number).BackColor = backColor
  543.            .Styles(Style.Vb.Number).ForeColor = Color.OrangeRed
  544.            .Styles(Style.Vb.Number).Bold = False
  545.            .Styles(Style.Vb.Number).Italic = False
  546.            .Styles(Style.Vb.Number).Underline = False
  547.  
  548.            .Styles(Style.Vb.Operator).BackColor = backColor
  549.            ' .Styles(Style.Vb.Operator).ForeColor = Color.DarkKhaki
  550.            ' .Styles(Style.Vb.Operator).ForeColor = Color.DarkCyan
  551.            ' .Styles(Style.Vb.Operator).ForeColor = Color.Honeydew
  552.            ' .Styles(Style.Vb.Operator).ForeColor = Color.LightSteelBlue
  553.            .Styles(Style.Vb.Operator).ForeColor = Color.Gray
  554.            .Styles(Style.Vb.Operator).Bold = True
  555.            .Styles(Style.Vb.Operator).Italic = False
  556.            .Styles(Style.Vb.Operator).Underline = False
  557.  
  558.            .Styles(Style.Vb.Preprocessor).BackColor = backColor
  559.            ' .Styles(Style.Vb.Preprocessor).ForeColor = Color.HotPink
  560.            .Styles(Style.Vb.Preprocessor).ForeColor = Color.Gray
  561.            .Styles(Style.Vb.Preprocessor).Bold = False
  562.            .Styles(Style.Vb.Preprocessor).Italic = False
  563.            .Styles(Style.Vb.Preprocessor).Underline = False
  564.  
  565.            .Styles(Style.Vb.String).BackColor = backColor
  566.            .Styles(Style.Vb.String).ForeColor = Color.Brown
  567.            .Styles(Style.Vb.String).Bold = False
  568.            .Styles(Style.Vb.String).Italic = False
  569.            .Styles(Style.Vb.String).Underline = False
  570.  
  571.            .Styles(Style.Vb.StringEol).BackColor = backColor
  572.            .Styles(Style.Vb.StringEol).ForeColor = Color.Black
  573.            .Styles(Style.Vb.StringEol).FillLine = True
  574.            .Styles(Style.Vb.StringEol).Bold = False
  575.            .Styles(Style.Vb.StringEol).Italic = False
  576.            .Styles(Style.Vb.StringEol).Underline = False
  577.  
  578.        End With
  579.  
  580.        ' Set the Vb.Net keywords.
  581.        editor.SetKeywords(0, keywords)
  582.        editor.SetKeywords(1, typenames)
  583.        editor.SetKeywords(2, literals)
  584.        editor.SetKeywords(3, other)
  585.  
  586.    End Sub
« Última modificación: 8 Marzo 2016, 13:41 pm por Eleкtro » En línea

nolasco281


Desconectado Desconectado

Mensajes: 319


Ver Perfil
Re: Agregar palabras reservadas a un richtextbox
« Respuesta #5 en: 8 Marzo 2016, 19:39 pm »

Hola Eleкtro.

Gracias a las recomendaciones, ya habia logrado hacer algo, no tanto como lo que compartes en este momento pero lo suficiente para saber como funcionan algunas cosas, Ya he probado el ejemplo que compartes y estoy tratando de entender algunas cosas por mi cuenta.

Te agradezco mucho la ayuda y por mencionar Roslyn de Microsoft como investigacion me viene bien.

Saludos.
En línea

Lo que se puede imaginar... se puede programar.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

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