Previous Document Next Document

Object Model Reference : Classes : S : Shape : Methods : Shape.SetBoundingBox


Shape.SetBoundingBox

Sub SetBoundingBox(x As Double, y As Double, Width As Double, Height As Double, [KeepAspect As Boolean = False], [ReferencePoint As cdrReferencePoint = cdrCenter])

Description

Member of Shape

The SetBoundingBox method moves and resizes a shape so that it fits the specified bounding box.

 
You can resize a shape with or without maintaining its proportions. The default shape position within the bounding box can be specified.

Parameter
Description
x
Specifies, in document units, the horizontal position, or x-coordinate, of the center of the bounding box
y
Specifies, in document units, the vertical position, or y-coordinate, of the center of the bounding box
Width
Specifies, in document units, the width of the bounding box
Height
Specifies, in document units, the height of the bounding box
KeepAspect
Specifies whether the size proportions of the bounding box are maintained relative to its contents. This parameter is optional, and its default value is False.
ReferencePoint
Specifies the reference point. This parameter is optional, and its default value is cdrCenter (9).

VBA example

The following VBA example creates a new document and imports all images from the specified folder, arranging them in an array of thumbnails on the page.

Sub Test()
 Const NumX As Long = 4 ' Number of thumbnails horizontally
 Const NumY As Long = 5 ' Number of thumbnails vertically
 Const Margin As Double = 0.5 ' Page margin in inches
 Const Gutter As Double = 0.1 ' Thumbnail gutter in inches
 Const Caption As Double = 0.2 ' Image caption size in inches
 Const Folder As String = "C:\Temp\Images\" ' Folder path
 Dim s As Shape, doc As Document
 Dim nx As Long, ny As Long
 Dim x As Double, y As Double, sx As Double, sy As Double
 Dim f As String
 nx = 0
 ny = 0
 Set doc = CreateDocument()
 sx = (doc.ActivePage.SizeWidth - 2 * Margin - (NumX - 1) * Gutter) / NumX
 sy = (doc.ActivePage.SizeHeight - 2 * Margin - (NumY - 1) * Gutter) / NumY
 ' Find first file in the folder
 f = Dir(Folder & "*.*")
 While f <> ""
  x = Margin + nx * (Gutter + sx)
  y = Margin + ny * (Gutter + sy)
  ' Create a rectangle to hold a thumbnail
  doc.ActiveLayer.CreateRectangle2 x, y + Caption, sx, sy - Caption
  ' Place a file name caption below the rectangle
  With doc.ActiveLayer.CreateArtisticText(x + sx / 2, y, f).Text
   .AlignProperties.Alignment = cdrCenterAlignment
   With .FontProperties
    .Name = "Arial"
    .Size = 10
   End With
  End With
  doc.ClearSelection
  ' Import the file
  doc.ActiveLayer.Import Folder & f
  If Not doc.ActiveShape Is Nothing Then
   ' If anything is imported, place it inside the rectangle
   ActiveShape.SetBoundingBox x, y + Caption, sx, sy - Caption, True, cdrCenter
  End If
  nx = nx + 1
  If nx = NumX Then
   nx = 0
   ny = ny + 1
   If ny = NumY Then
    doc.AddPages 1 ' Add the page if the current one is full
    ny = 0
   End If
  End If
  ' Find next file
  f = Dir()
 Wend
End Sub

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.