StringGadget Questions
StringGadget Questions
I'm sure these are easy ones to answer.
1. If I have some text in a multiple line string gadget and I use the command setgadgettext it overwrites the content already in the string gadget, is their a way to append text to a string gadget or insert text into a string gadget at the cursor position ?
2. Is their a way of reading highlighted text in a multiple line string gadget, I'm also testing another language which has feature that does this, its called 'get chunk', is their a way to read highlighted text in Pure basic.
Any help would be greatly appreciated.
Kind regards
1. If I have some text in a multiple line string gadget and I use the command setgadgettext it overwrites the content already in the string gadget, is their a way to append text to a string gadget or insert text into a string gadget at the cursor position ?
2. Is their a way of reading highlighted text in a multiple line string gadget, I'm also testing another language which has feature that does this, its called 'get chunk', is their a way to read highlighted text in Pure basic.
Any help would be greatly appreciated.
Kind regards
Thanks but . . .
dmoc that works great, all I need to know now is how to insert text at the cursor position.
I'm making an HTML editor which has a insert menu, you can select insert bold tags and it inserts <b></b> but at the moment it adds it to the end of the string gadget, I need it to insert it at the mouse position.
Kind regards
I'm making an HTML editor which has a insert menu, you can select insert bold tags and it inserts <b></b> but at the moment it adds it to the end of the string gadget, I need it to insert it at the mouse position.
Kind regards
Guess this does the trick...
Timo
Code: Select all
; PureBasic Visual Designer v3.70a Beta
;- Window Constants
;
#Window_0 = 0
;- Gadget Constants
;
#Gadget_1 = 0
#original = 1
#start = 2
Procedure Open_Window_0()
If OpenWindow(#Window_0, 402, 160, 293, 79, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
If CreateGadgetList(WindowID())
TextGadget(#Gadget_1, 10, 10, 100, 30, "Enter String and select a piece:")
StringGadget(#original, 110, 10, 170, 20, "")
ButtonGadget(#start, 110, 40, 70, 20, "make bold")
EndIf
EndIf
EndProcedure
Open_Window_0()
Repeat
Event = WaitWindowEvent()
If event = #PB_EventGadget And EventGadgetID() = #start
original.s = GetGadgetText(#original) ; get strings from Gadget
new.s = ""
; get selected position from #original Gadget
SendMessage_(GadgetID(#original), #EM_GETSEL, @startpos.l, @endpos.l)
new = Left(original, startpos) ; unselected part on the left
new + "<B>" ; bold mark
new + Mid(original, startpos+1, endpos-startpos) ; marked text
new + "</B>" ; unbold mark
new + Right(original, Len(original)-endpos) ; unselected part on the right
SetGadgetText(#original, new) ; set new text
; set selection again (3 characters right of original position, because we
; added the <b>
SendMessage_(GadgetID(#original), #EM_SETSEL, startpos+3, endpos+3)
ActivateGadget(#original) ; activate Gadget again
EndIf
Until Event = #PB_EventCloseWindow
End
quidquid Latine dictum sit altum videtur
Thanks for your reply but . . .
Thanks for your reply freak but . . .
I sat down and learnt how to use the richedit library, it doe's just what I want in two lines !!!
Kind regards
I sat down and learnt how to use the richedit library, it doe's just what I want in two lines !!!
Kind regards
Re: Thanks for your reply but . . .
Freak's tip updated for the latest PureBasic (v5.61):
Code: Select all
#Window_0 = 0
;- Gadget Constants
;
#Gadget_1 = 0
#original = 1
#start = 2
Procedure Open_Window_0()
If OpenWindow(#Window_0, 402, 160, 293, 79, "New window ( 0 )", #PB_Window_SystemMenu)
TextGadget(#Gadget_1, 10, 10, 100, 30, "Enter String and select a piece:")
StringGadget(#original, 110, 10, 170, 20, "this is a little test")
ButtonGadget(#start, 110, 40, 70, 20, "make bold")
EndIf
EndProcedure
Open_Window_0()
Repeat
Event = WaitWindowEvent()
If event = #PB_Event_Gadget And EventGadget() = #start
original.s = GetGadgetText(#original) ; get strings from Gadget
new.s = ""
; get selected position from #original Gadget
SendMessage_(GadgetID(#original), #EM_GETSEL, @startpos.l, @endpos.l)
new = Left(original, startpos) ; unselected part on the left
new + "<B>" ; bold mark
new + Mid(original, startpos+1, endpos-startpos) ; marked text
new + "</B>" ; unbold mark
new + Right(original, Len(original)-endpos) ; unselected part on the right
SetGadgetText(#original, new) ; set new text
; set selection again (3 characters right of original position, because we
; added the <b>
SendMessage_(GadgetID(#original), #EM_SETSEL, startpos+3, endpos+3)
SetActiveGadget(#original) ; activate Gadget again
EndIf
Until Event = #PB_Event_CloseWindow
Re:
BTW, wasn't there a quicker way to append text to the end of a StringGadget without doing this:
I'm sure I once did something with an API call to add text to the end, without reading the entire existing contents first, but I can't find anything in my sources now. I'm 99% sure it was something like SendMessage with #ES_SETTEXT or such. Anyone ever done it?
Code: Select all
SetGadgetText(#Gadget, GetGadgetText(#Gadget)+newtext)
Re: Thanks for your reply but . . .
Error on line 30:Dude wrote:Freak's tip updated for the latest PureBasic (v5.61):
SendMessage_() is not a function, array, list, map or macro.
How can I arrange this?
My purebasic is version demo 5.51.
Windows 7 64
Right now, I appreciate any help.
Using google translate.
__________________________________________________
Quote tag repaired
20.11.2018
RSBasic
Re: Thanks for your reply but . . .
The use of the Windows-API is not available in the Purebasic demo.MarcosPC wrote:My purebasic is version demo 5.51
Re: StringGadget Questions
Ok, thanks!