DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Horizontally Centering Report Objects via Script

Solved!
Go to solution

Hello

 

I wanted to be able to programmatically center report objects, such as a text box and a 2D curve plots, with each other.

 

Thanks

 

DIAdem 2015 SP2 32 bit

 

 

Tim
0 Kudos
Message 1 of 2
(2,777 Views)
Solution
Accepted by topic author smoothdurban

Center objects in Sheet center:

Dim oCtrl, PageWidth, ObjWidth
PageWidth = Report.ActiveSheet.Dimensions.Width
for each oCtrl in Report.ActiveSheet.Objects
	ObjWidth  = oCtrl.Position.ByCoordinate.Width
	oCtrl.Position.ByCoordinate.X1 = PageWidth / 2 - ObjWidth / 2
	oCtrl.Position.ByCoordinate.X2 = PageWidth / 2 + ObjWidth / 2
next
call Report.Refresh()

 Center objects at center of another object:

Dim oCtrl, CenterPos, ObjWidth, RefObject
set RefObject = Report.ActiveSheet.Objects("TextObject1")
CenterPos = RefObject.Position.ByCoordinate.X1 + RefObject.Position.ByCoordinate.Width / 2
for each oCtrl in Report.ActiveSheet.Objects
	if not oCtrl is RefObject then
		ObjWidth  = oCtrl.Position.ByCoordinate.Width
		oCtrl.Position.ByCoordinate.X1 = CenterPos - ObjWidth / 2
		oCtrl.Position.ByCoordinate.X2 = CenterPos + ObjWidth / 2
	end if
next
call Report.Refresh()
Christian
CLA, CTA, CLED
Message 2 of 2
(2,747 Views)