[Gambas-user] Inserting an Image into the TextEdit control
Maximillian Von Kloisterheim
maximvonk at ...626...
Tue Apr 8 17:56:43 CEST 2008
Benoit Minisini wrote:
> There is no official support for inserting images in a TextEdit. There was in
> Gambas 1, maybe it could work in Gambas 2.
>
> Regards,
>
Thanks Benoit. Now I know that Iv hacked at it and made a workaround:
DIM imgName AS String
DIM CON AS String
DIM CAN AS String
'Get the filename
Dialog.Filter = ["*.jpg;*.gif;*.bmp;*.png", "Image Files"]
Dialog.OpenFile()
imgName = Dialog.Path
IF imgName = "" THEN RETURN
'Insert this (Or any similar place holder) at the current position
txt_EDIT.Insert("KIIMD")
'Collect the contents of the TextEdit control
CON = txt_EDIT.Text
'Replace the place holder with the image file path
CAN = Replace$(CON, "KIIMD", "<img src=" & imgName & ">")
'reset the text
txt_EDIT.Text = CAN
This works, apparently without causing any problems. The images are
treated as text blocks, so they can be aligned etc, but I cant see a way
of changing sizes or text run-arounds etc.
One other thing: The HTML style format used by the TextEdit control will
strip away any quote marks that might be around the image path, so there
is no point in putting them in.
Of course if my reckless hacking is likely to cause strange problems in
some way Iv yet to find, please let me know.
Regards
Max
More information about the User
mailing list