Verfasst: 07.11.2014 11:36
~ DELETE ~
Code: Alles auswählen
newText="Dies ist eine farbige Zeile"
farbe=RGB(0,255,0)
i = Len(lobbychatEdi.Text)
lobbychatEdi.SelStart = i
lobbychatEdi.SelLength = Len(newText)
lobbychatEdi.SelColor = farbe
lobbychatEdi.SelText = newText
Habe mal schnell dieses Beispiel von freak etwas abgeändert.stevie1401 hat geschrieben:Kann mir jemand ein begreifbares Beispiel geben?
Code: Alles auswählen
Procedure SciColorLine(gadget, line, style)
ScintillaSendMessage(gadget, #SCI_STARTSTYLING, ScintillaSendMessage(gadget,#SCI_POSITIONFROMLINE,line), $FF)
ScintillaSendMessage(gadget, #SCI_SETSTYLING, ScintillaSendMessage(gadget,#SCI_LINELENGTH,line), style)
EndProcedure
If OpenWindow(0, 0, 0, 400, 500, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla()
ScintillaGadget(0, 10, 10, 380, 480, 0)
; set text
*Buffer = AllocateMemory(1000)
PokeS(*Buffer, "Zeile 1" + Chr(10) + "Zeile 2" + Chr(10) + "Zeile 3" + Chr(10) + "Zeile 4" + Chr(10), -1, #PB_Ascii)
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Buffer)
; normaler text style (style 0)
PokeS(*Buffer, "Lucida Console", -1, #PB_Ascii)
ScintillaSendMessage(0, #SCI_STYLESETFONT, 0, *Buffer)
ScintillaSendMessage(0, #SCI_STYLESETSIZE, 0, 14)
; Style 1 erstellen, gruen
ScintillaSendMessage(0, #SCI_STYLESETFONT, 1, *Buffer)
ScintillaSendMessage(0, #SCI_STYLESETSIZE, 1, 14)
ScintillaSendMessage(0, #SCI_STYLESETFORE, 1, RGB(0,255,0))
; Style 2 erstellen, rot
ScintillaSendMessage(0, #SCI_STYLESETFONT, 2, *Buffer)
ScintillaSendMessage(0, #SCI_STYLESETSIZE, 2, 14)
ScintillaSendMessage(0, #SCI_STYLESETFORE, 2, RGB(255,0,0))
; Style 3 erstellen, blau
ScintillaSendMessage(0, #SCI_STYLESETFONT, 3, *Buffer)
ScintillaSendMessage(0, #SCI_STYLESETSIZE, 3, 14)
ScintillaSendMessage(0, #SCI_STYLESETFORE, 3, RGB(0,0,255))
; Styles für Zeilen setzen
SciColorLine(0,0,1)
SciColorLine(0,1,2)
SciColorLine(0,2,3)
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Alles auswählen
Procedure SciText(text.s)
Static *Buffer
If Not *Buffer
*Buffer = AllocateMemory(1024 * 10)
EndIf
PokeS(*Buffer, text, -1, #PB_Ascii)
ProcedureReturn *Buffer
EndProcedure
Procedure SciColorLine(gadget, line, style)
ScintillaSendMessage(gadget, #SCI_STARTSTYLING, ScintillaSendMessage(gadget,#SCI_POSITIONFROMLINE,line), $FFFF)
ScintillaSendMessage(gadget, #SCI_SETSTYLING, ScintillaSendMessage(gadget,#SCI_LINELENGTH,line), style)
EndProcedure
Procedure SciAddLineWithStyle(gadget, text$, style)
text$ + Chr(10)
ScintillaSendMessage(gadget, #SCI_SETSEL,-1,-1)
line = ScintillaSendMessage(gadget, #SCI_LINEFROMPOSITION, ScintillaSendMessage(gadget,#SCI_GETCURRENTPOS))
ScintillaSendMessage(gadget, #SCI_APPENDTEXT, Len(text$),SciText(text$))
SciColorLine(gadget, line, style)
EndProcedure
RandomSeed(1111)
If OpenWindow(0, 0, 0, 800, 600, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla()
ScintillaGadget(0, 10, 10, 780, 580, 0)
; Init und Standardfont setzen
ScintillaSendMessage(0, #SCI_STYLERESETDEFAULT)
ScintillaSendMessage(0, #SCI_STYLESETFONT,#STYLE_DEFAULT, SciText("Arial"))
ScintillaSendMessage(0, #SCI_STYLESETSIZE,#STYLE_DEFAULT, 24)
ScintillaSendMessage(0, #SCI_STYLECLEARALL)
; die styles initialisieren / Farben setzen
For style = 0 To 31
ScintillaSendMessage(0, #SCI_STYLESETFORE, style, RGB( Random(255), Random(255), Random(255) ) ) ; Vordergrundfarbe für den Style setzen
;ScintillaSendMessage(0, #SCI_STYLESETBACK, style, RGB( Random(255), Random(255), Random(255) ) ) ; Hintergrundfarbe für den Style setzen
Next
; Zeilen hinzufügen
For i = 0 To 31
SciAddLineWithStyle(0, "Eine neue Zeile..."+Str(i), Random(31))
Next
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Alles auswählen
EnableExplicit
Global Dim ScintillaRememberColorString.s(3,500)
Global Dim ScintillaRememberColorCount(3)
Declare CheckScintillaColor(GadgetNo,aColor)
Declare ScintillaAddColoredLine(ScintillaNo,aText.s,aColor)
Define l,i,txtLen,startpos,r,g,b,col,ScNo,ColStyle,nlen
Define text.s,scin1txt.s,ScintillaNo
ScNo=1
If OpenWindow(0, 0, 0, 600, 600, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla()
ScintillaGadget(1, 10, 10, 250, 400, #Null)
ScintillaSendMessage(ScNo, #SCI_SETWRAPMODE, #True)
For i=1 To 200
col=RGB(Random(200,1),Random(200,1),Random(200,1))
ScintillaAddColoredLine(1,"Das ist eine längere Zeile, um Wprapmode und die Zeile zu testen.Dies ist übrigens Zeile: "+Str(i),col)
Next i
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Procedure ScintillaAddColoredLine(ScintillaNo,aText.s,aColor)
Protected ColStyle,startpos,txtlen,i
Protected.s text
text=aText+Chr(10)
ColStyle=CheckScintillaColor(ScintillaNo,aColor)
startpos=ScintillaSendMessage(ScintillaNo,#SCI_GETLENGTH) -1
txtlen = Len(text)
ScintillaSendMessage(ScintillaNo, #SCI_APPENDTEXT, txtlen, @Text)
ScintillaSendMessage(ScintillaNo,#SCI_STARTSTYLING,startpos,255)
ScintillaSendMessage(ScintillaNo,#SCI_SETSTYLING,txtlen,ColStyle)
EndProcedure
Procedure CheckScintillaColor(GadgetNo,aColor)
Protected i,foundColor,StyleNumber
For i=1 To ScintillaRememberColorCount(GadgetNo)
If ScintillaRememberColorString(GadgetNo,i)=Str(aColor) ;Die Farbe gibt es schon im ScintillaGadget
foundColor=aColor
StyleNumber=i
EndIf
Next i
If foundColor=0
ScintillaRememberColorCount(GadgetNo)+1
StyleNumber=ScintillaRememberColorCount(GadgetNo)
ScintillaRememberColorString(GadgetNo,StyleNumber)=Str(aColor)
ScintillaSendMessage(GadgetNo, #SCI_STYLESETFORE, StyleNumber, aColor)
EndIf
ProcedureReturn StyleNumber
EndProcedure
Das ist bei mir auch so, mit PB 5.2x LTS. Benutzt Du schon PB 5.31?stevie1401 hat geschrieben:Ich bekomme allerdings nach der 31. Farbe (Style) Fehler.