OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   adding jpg to textbox (http://forum.oberonplace.com/showthread.php?t=1658)

donjuan 31-07-2006 09:04

adding jpg to textbox
 
Has anyone try to insert a jpg file or bmp file to a textbox
This can be manually in corel 11.

I have this code where mytext is my textbox where I insert addingtext,

How would it be my syntaxis to insert into textbox a file instead a text


mytext.Text.Story.InsertAfter "addingtext"

Alex 21-08-2006 23:03

The only way you can do this is through the clipboard. Copy your bitmap (or other object) to the clipboard (using Shape.Copy or Shape.Cut methods) and then paste it into the text object using TextRange.Paste method.

Note that TextRange.Paste replaces the whole content of the text range with the objects from the clipboard (that is, as if the whole text in the range was selected and then you start typing - which effectively replaces the selected characters with the new ones).

If you want to paste an object after a range, you need to construct a range which will point right past the end of the current range. You can use TextRange.Collapse method to do it quickly.

Here is a sample macro which creates a rectangle, converts it into a bitmap. Copies the bitmap to the clipboard and creates a paragraph text object with some text in it, then pastes the bitmap at the end of the text object:

Code:

Sub InsertBitmapIntoText()
    Dim s As Shape
    Dim sBitmap As Shape
    Dim tr As TextRange
   
    Set s = ActiveLayer.CreateRectangle(0, 0, 2, 2)
    s.Fill.ApplyTextureFill "Aerial clouds", "Samples"
    Set sBitmap = s.ConvertToBitmapEx(cdrCMYKColorImage, Resolution:=120)
   
    Set s = ActiveLayer.CreateParagraphText(0, 2, 2, 4, "Some Text")
    Set tr = s.Text.Story
    tr.Collapse True ' Make an empty text range which is at the end of the text
   
    sBitmap.Cut
    tr.Paste ' Paste the bitmap into the current (empty) text range
End Sub



All times are GMT -5. The time now is 06:13.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com