Scintilla是一个免费、跨平台、支持语法高亮的编辑控件。它完整支持源代码的编辑和调试,包括语法高亮、错误指示、代码完成(code completion)和调用提示(call tips)。能包含标记(marker)的页边(margin)可用于标记断点、折叠和高亮当前行。

VFB 里的代码编辑,就是使用这个控件。功能非常多,非常强大。
编译成软件后,会在软件文件夹产生一个 支持库DLL,发行软件需要带这个DLL。
主要事件
文本或样式已更改
Sub Form1_Scintilla1_SCN_Updateui(hWndForm As hWnd, hWndControl As hWnd, sN As SCNOTIFICATION )
End Sub
主要属性
Scintilla1.GetLineCount 总行数
Scintilla1.Text 获取或设置文本,UTF8编码
Scintilla1.SendMessage 发送消息
Scintilla 设置非常多,都是通过 Scintilla1.SendMessage 来处理,具体设置需要到官网查看编程文档。这里控件已经给你处理好了事件和消息。后面就按编程文档说明,发送消息即可。
点此打开火花编辑器官方网址
常用设置参考
SciMsg 函数是Scintilla 内部定义的函数和 Scintilla1.SendMessage 是一样的功能,可以按照自己喜欢的方式写。
Dim pSci As Any Ptr = Scintilla1.pSci
SciMsg(pSci, SCI_STYLESETFORE, STYLE_DEFAULT, 窗体文字)
SciMsg(pSci, SCI_STYLESETBACK, STYLE_DEFAULT, 窗体底色)
Dim tStr As ZString * 1024 = "Microsoft YaHei Mono"
SciMsg(pSci, SCI_STYLESETFONT, STYLE_DEFAULT, Cast(lParam, @tStr))
SciMsg(pSci, SCI_STYLESETSIZE, STYLE_DEFAULT, 10)
SciMsg(pSci, SCI_STYLESETCHARACTERSET, STYLE_DEFAULT, SC_CHARSET_DEFAULT)
SciMsg(pSci, SCI_STYLECLEARALL, 0, 0) ' 将全局样式复制到所有其他样式
'行号宽度
tStr = "_9"
Dim nPixels As Long = SciMsg(pSci, SCI_TEXTWIDTH, 0, Cast(lParam, @tStr))
SciMsg(pSci, SCI_SETMARGINWIDTHN, 0, nPixels)
' 书签
SciMsg(pSci, SCI_SETMARGINWIDTHN, 1, 2)
'行号颜色
SciMsg(pSci, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER)
SciMsg(pSci, SCI_STYLESETFORE, STYLE_LINENUMBER, 窗体文字)
SciMsg(pSci, SCI_STYLESETBACK, STYLE_LINENUMBER, 窗体亮度15)
'' TABS 作为空格处理
SciMsg(pSci, SCI_SETUSETABS, CTRUE, 0)
'' TAB 宽度
SciMsg(pSci, SCI_SETTABWIDTH, 3, 0)
SciMsg(pSci, SCI_SETINDENT, 3, 0)
' 显示缩进参考线
SciMsg(pSci, SCI_SETINDENTATIONGUIDES, CTRUE, 0)
'' 当前行颜色
SciMsg(pSci, SCI_SETCARETLINEBACK, 窗体亮度10, 0)
SciMsg(pSci, SCI_SETHOTSPOTACTIVEUNDERLINE, CTRUE, 0) '允许
''' 选择颜色
'SciMsg(pSci, SCI_SETSELFORE, CTRUE, op.Themes(0).colors(CLR_SELECTION).nFg)
'SciMsg(pSci, SCI_SETSELBACK, CTRUE, op.Themes(0).colors(CLR_SELECTION).nBg)
'SciMsg(pSci, SCI_SETHOTSPOTACTIVEUNDERLINE, CTRUE, 0) '允许
'' 始终保持插入符号行可见
SciMsg(pSci, SCI_SETCARETLINEVISIBLEALWAYS, CTRUE, 0)
'' 标识要在单词中使用的字符
tStr = "&~_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
SciMsg(pSci, SCI_SETWORDCHARS, 0, Cast(lParam, @tStr))
'为了在编辑器中显示,utf8或utf16将被转换为utf8。
SciMsg(pSci, SCI_SETCODEPAGE, SC_CP_UTF8, 0)
'SciMsg(pSci, SCI_SETSCROLLWIDTHTRACKING, True, 0) '滚动宽度跟踪,则调整滚动宽度以确保当前显示的所有行都可以完全滚动。
SciMsg(pSci, SCI_SETSCROLLWIDTH, 10000, 10000)
SciMsg(pSci, SCI_SETVSCROLLBAR, 0, 0)
SciMsg(pSci, SCI_SETHSCROLLBAR, 0, 0)
SciMsg(pSci, SCI_SETLEXER, SCLEX_VB, 0)
'设置FreeBASIC关键字
If Len(FreeBASIC关键字)=0 Then
FreeBASIC关键字 = "abs abstract access acos add alias allocate alpha and and and andalso any append as asc asin asm assert assertwarn atan2 atn bload bsave base bin "
FreeBASIC关键字 &= "binary bit bitreset bitset byref byval byref byte callocate cbyte cdbl cint clng clngint cptr cshort csign csng cubyte cuint culng culngint cushort "
FreeBASIC关键字 &= "cunsg cvd cvi cvl cvlongint cvs cvshort call case cast chdir chain chartoutf chr circle class clear close cls color command common condbroadcast "
FreeBASIC关键字 &= "condcreate conddestroy condsignal condwait const const const constructor constructor continue cos csrlin curdir custom data date dateadd datediff "
FreeBASIC关键字 &= "datepart dateserial datevalue day deallocate declare defbyte defdbl defint deflng defshort defsng defstr defubyte defuint defushort deflongint defulongint "
FreeBASIC关键字 &= "delete destructor destructor dim dir do double draw draw dylibfree dylibload dylibsymbol eof else elseif encoding end end end if endif enum...end "
FreeBASIC关键字 &= "environ eqv eqv erase erfn erl ermn error event exepath exec exit exp export extends extern field fileattr filecopy filedatetime fileexists filelen "
FreeBASIC关键字 &= "fix flip for for format frac fre freefile function function get getjoystick getkey getmouse gosub goto hex hibyte hiword hour iif if imageconvertrow "
FreeBASIC关键字 &= "imagecreate imagedestroy imp imp implements import instr instrrev inkey inp input int integer is isdate isredirected kill lbound lcase loc lof lprint "
FreeBASIC关键字 &= "lset ltrim left len let let lib line lobyte loword locate lock log long longint loop lpos mkd mki mkl mklongint mks mkshort mid mid minute mkdir "
FreeBASIC关键字 &= "mod mod month monthname multikey mutexcreate mutexdestroy mutexlock mutexunlock naked name namespace new next next not now object oct offsetof on "
FreeBASIC关键字 &= "once open operator option or orelse out output overload override pcopy pmap preset pset pset paint palette peek placement point pointcoord pointer "
FreeBASIC关键字 &= "poke pos preserve print print print private private: procptr property protected: ptr public put put rgb rgba rset rtrim random randomize redim read "
FreeBASIC关键字 &= "reallocate rem reset restore resume return right rmdir rnd run sadd scope screen screencontrol screencopy screenevent screenglproc screeninfo screenlist "
FreeBASIC关键字 &= "screenlock screenptr screenres screenset screensync screenunlock second seek seek select setdate setenviron setmouse settime sgn shared shell shl "
FreeBASIC关键字 &= "shl short shr shr sin single sizeof sleep space spc sqr static static step step stick stop str strptr strig string sub sub swap system tab tan then "
FreeBASIC关键字 &= "this threadcreate threadwait threadcall threaddetach time timeserial timevalue timer to trans trim type typeof ubound ubyte ucase uinteger ulong "
FreeBASIC关键字 &= "ulongint ushort union unlock unsigned until using val valint vallng valuint valulng var varptr view virtual wbin wchr whex woct wspace wstr wstring "
FreeBASIC关键字 &= "wait weekday weekdayname wend while width window windowtitle winput with write wstring xor year zstring cdecl defined pascal stdcall va_arg va_first "
FreeBASIC关键字 &= "va_next "
End If
'If Len(op.FBKeywordsC) Then
SciMsg(pSci, SCI_SETKEYWORDS, 0, Cast(lParam, StrPtr(FreeBASIC关键字)))
'End If
'If Len(op.APIKeywordsC) Then
' SciMsg(pSci, SCI_SETKEYWORDS, 1, Cast(lParam, StrPtr(op.APIKeywordsC)))
'End If
'设置多行注释样式
SciMsg(pSci, SCI_STYLESETFORE, SCE_B_MULTILINECOMMENT, BGR(77, 153, 0))
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_MULTILINECOMMENT, op.Themes(0).colors(CLR_COMMENTS).nBg)
'设置注释样式
SciMsg(pSci, SCI_STYLESETFORE, SCE_B_COMMENT, BGR(77, 153, 0))
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_COMMENT, op.Themes(0).colors(CLR_COMMENTS).nBg)
'设置关键字样式
SciMsg(pSci, SCI_STYLESETFORE, SCE_B_KEYWORD, BGR(0, 0, 229))
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_KEYWORD, op.Themes(0).colors(CLR_KEYWORD).nBg)
'设置标识符样式
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_IDENTIFIER, op.Themes(0).colors(CLR_TEXT).nBg)
'设置数字样式
SciMsg(pSci, SCI_STYLESETFORE, SCE_B_NUMBER, BGR(0, 178, 178))
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_NUMBER, op.Themes(0).colors(CLR_TEXT).nBg)
'设置运算符样式
SciMsg(pSci, SCI_STYLESETFORE, SCE_B_OPERATOR, BGR(178, 0, 178))
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_OPERATOR, op.Themes(0).colors(CLR_OPERATORS).nBg)
'设置预处理样式
SciMsg(pSci, SCI_STYLESETFORE, SCE_B_PREPROCESSOR, BGR(102, 0, 204))
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_PREPROCESSOR, op.Themes(0).colors(CLR_PREPROCESSOR).nBg)
'设置字符串样式
SciMsg(pSci, SCI_STYLESETFORE, SCE_B_STRING, BGR(178, 0, 89))
'SciMsg(pSci, SCI_STYLESETBACK, SCE_B_STRING, op.Themes(0).colors(CLR_STRINGS).nBg)
评论一下?