Page 1 of 1
Inserting Bitmap in position of caret
Posted: Tue Jun 14, 2011 3:26 pm
by Prometeus
Hello,
I am trying to insert a Bitmap from Clipboard into a TRichView document in the position of caret but always it inserts in the beginning of the document.
I write some lines of text in the document and at the end of it I need to insert a picture. I copy the picture to Clipboad as Bitmap and I am using 'MyDoc.PasteBitmap' to insert the piture in the position of caret but to no avail.
I tried put the caret at the document's end by hand (as below) but to no avail as well.
---
if (RVDoc.ItemCount > 0) then
begin
RVDoc.Format;
ItemNo := RVTrab.ItemCount - 1;
Offs := RVTrab.GetOffsAfterItem(ItemNo);
RVDoc.SetSelectionBounds(ItemNo,Offs,ItemNo,Offs);
RVDoc.Format;
end;
---
Is there some additional step in order to get the 'PasteBitmap' function work?
Another question: to make the picture centered in the page can I use the 'Aligment' property from 'TParaInfo'?
Thanks for any help.
Posted: Wed Jun 15, 2011 12:52 pm
by Prometeus
Hello,
An workaround to this that I found is using the function 'AddPictureEx' that is really adding the picture to the end of document.
However, I can't centralize the inserted picture horizontally. How to do that?
Thanks!
Posted: Wed Jun 15, 2011 5:07 pm
by Sergey Tkachenko
AddPictureEx is designed for document generation.
If you want to insert picture in the caret position, use InsertPicture, or PasteBitmap method.
PS: Format moves the caret to the beginning of the document.
It's enough to call
Code: Select all
ItemNo := RVTrab.ItemCount - 1;
Offs := RVTrab.GetOffsAfterItem(ItemNo);
RVDoc.SetSelectionBounds(ItemNo,Offs,ItemNo,Offs);
Formatted editor always has at least one item (empty text item), so it's safe to assume ItemCount>0.
Posted: Wed Jun 15, 2011 5:49 pm
by Prometeus
Hello Sergey,
Thanks, it worked! ALL the trouble was caused by the unnecessary 'Format' you pointed out, including the horizontally centering.
Thanks for the 'ItemCount' tip as well.
Best Regards!
Posted: Fri Jun 17, 2011 2:58 pm
by Prometeus
Hello, Sergey,
As I told before I can insert a picture in a document without problems, but I need ALL pictures be centralized horizontally. The document is been built like below:
---
some text;
picture
some text;
picture
some text;
picture
...
---
The problem is that all the text has the correct alignment that I want, but ALL picture is left aligned except the last one that is center aligned as expected. Looks like the doc looses the alignment when there is more text after the picture. I think this because the text following the picture is center aligned but the picture is always left aligned altough I set the picture's aligment to center.
I tried lots of things but I can't get the picture center aligned horizontally except the last one.
Do you have some tip for this?
Regards.
Posted: Fri Jun 17, 2011 4:44 pm
by Sergey Tkachenko
To center a picture horizontally, it must be inserted in a paragraph having Alignment = rvaCenter.
Do you generate a new document, or insert in existing document?
Posted: Fri Jun 17, 2011 5:17 pm
by Prometeus
Hello,
The document is build from scratch. It is not an existing document. I am using the 'rvaCenter' in the paragraph aligment, but I don't know why just after the picture been inserted, if I insert a new text after it the just inserted picture looses the alignment and changes it to rvaLeft. All the text inserted, each one with different alignments, are correct. This problem just occurs with the inserted pictures. I am using the 'PasteBitmap' function to copy a picture that is generated in my application and then paste it into the document been generated. The picture is inserted on the caret position but looses the alignment, except the last one that doesn't have text after it.
What could be the cause of this problem?
Thanks.
Posted: Fri Jun 17, 2011 6:05 pm
by Sergey Tkachenko
If you build document from scratch, it's better to use different methods: AddPictureEx and AddTextNL. These methods have ParaNo parameter, where you can specify an index (in RVStyle.ParaStyles) of paragraph style with center or left alignment.
When generation is finished, call Format.
If you insist on using editing methods, they should be like:
Code: Select all
rve.InsertText(...);
rve.InsertText(#13);
rve.ApplyParaStyle(index of centered para);
rve.PasteBitmap (or rve.InsertPicture);
rve.InsertText(#13);
rve.ApplyParaStyle(index of left-aligned para);
rve.InsertText(...);
...