Date: 02-16-2022
Return to Index
created by gbSnippets
'The vertical/horizontal scrollbars are displayed only if needed. You can hide them,
'but you cannot make them stay visible when they are not needed.
'There are several kinds of scrolling actions you can take by code:
' - scroll up/down a specified number of lines
' - scroll left/right a specified number of columns
' - scroll to make caret (current position) visible
' - scroll to until a specific line is at the top of the window
' - move cursor to a specific position
' - move cursor to a specific line
'A variety of options are available when scrolling the caret. See the Scintilla
'online documentation for more details.
'Finally, there are also a few settings available
' - offset (from left edge) where text is displayed
' - assumed width of text content (for setting horizontal scrollbar properties)
' - accurately track line width (for setting horizontal scrollbar properties)
' - allow vertical scrolling to go one page past the last line of content
'These settings are useful in specific occasions, but are generally not
'enabled by most applications.
'Primary Code:
'Control horizontal scrollbar
SendMessage hSci, %SCI_SetHScrollbar, 1, 0 'default - displays when needed
SendMessage hSci, %SCI_SetHScrollbar, 0, 0 'hide
'Control horizontal scrollbar
SendMessage hSci, %SCI_SetVScrollbar, 1, 0 'default - displays when needed
SendMessage hSci, %SCI_SetVScrollbar, 0, 0 'hide
'This message is used to scroll a specified number of lines
SendMessage hSci, %SCI_LineScroll, 0, -5 'scroll up 5 lines
'Use this message is used to scroll the caret onto the screen
SendMessage hSci, %SCI_ScrollCaret, 0, 0 'scroll caret into view
'And this message will scroll the document to make the caret visible
SendMessage hSci, %SCI_ScrollCaret, 0, 0 'make caret visible
'Set first visible line
SendMessage hSci, %SCI_SetFirstVisibleLine, iLine, 0
'Move caret to specific position
SendMessage hSci, %SCI_GoToPosition, iPos, 0 'set caret to iPos, removes selection
'scroll to make caret visible, anchor=curpos
'Move caet to specific line
SendMessage hSci, %SCI_GoToLine, iLine, 0 'set caret at start of iLine, removes selection
'scroll to make caret visible, anchor=curpos
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "scintilla_gb.inc"
%ID_Sci = 1000 : %ID_BtnA = 1001 : %ID_BtnB = 1002
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,300,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %ID_BtnA, "Scroll +10", 10,10,90,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Set Caret to end", 10,40,90,20, %WS_Child Or %WS_Visible
Control Add "Scintilla", hDlg, %ID_Sci, "", 100,10,180,130, %WS_Child Or %WS_Visible
Control Handle hDlg, %ID_Sci To hSci 'get handle to Scintilla window
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local txt As String
txt = "Select Case var$ 'first line" + $CrLf + "End Select 'last line" + Chr$(0)
Select Case CB.Msg
Case %WM_InitDialog
InitializeScintilla
PostMessage hSci, %SCI_SetSel, 0,0 'unselect initially
Case %WM_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
End Select
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-110, Hi(Word, CB.lParam)-20
Case %WM_Destroy
If hLib Then FreeLibrary hLib 'free the Scintilla library
End Select
End Function
Sub InitializeScintilla
Local txt As String
txt = "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + $crlf + "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + $crlf + "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + $crlf + "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + $crlf + "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + $crlf + "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + "Else" + $crlf + " x = 0" + $crlf + "End If" + $crlf
txt = txt + "This is the last Line!" + Chr$(0)
SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
End Sub
Sub TestA
SendMessage hSci, %SCI_LineScroll, 0, 10 'scroll 10 lines
End Sub
Sub TestB
SendMessage hSci, %SCI_SetAnchor, 500, 0 'set caret position
SendMessage hSci, %SCI_SetCurrentPos, 500, 0 'set caret position
SendMessage hSci, %SCI_ScrollCaret, 0, 0 'make caret visible
Control Set Focus hDlg, %ID_Sci
End Sub
'gbs_00651
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm