Daniel,
��� The following is a subroutine I wrote specifically for that purpose.
It has the ability to center a text object vertically, horizontally, or
both.�
The rid variable is the rowid of the object in the layout table.� Below
is an example of how to use this in code.� I hope this helps you out.
�
Example:
�
dim LayTabName as string
LayTabName = windowinfo(frontwindow(),WIN_INFO_TABLE)
�
'this line places a text object into the window at the left margin, .5
inches from the top
Create Text into window frontwindow() "Map Title" (0,0.5)(8.5,11)
�
'call the subroutine using the frontwindow() to reference the current
window,
the tableinfo(LayTabName,tab_info_nrows) refers to the last object in the
layout table
(i.e. the one we just created), the 4.25 refers to 8.5 (width of the page)
divided by 2
which will center the text object on the page.� The -1 tells the program not
to alter
the text object vertically.
Call
CenterTextObj(frontwindow(),tableinfo(LayTabName,tab_info_nrows),4.25,-1)
�
�
'***************************************************************************
************
'� Written by John Hollingsworth� [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
'***************************************************************************
************
include "mapbasic.def"
declare sub CenterTextObj(byval layid as integer,byval rid as smallint,byval
Centerx,byval centery as float)
�
sub CenterTextObj(byval layid as integer,byval rid as smallint,byval
Centerx,byval centery as float)
�
dim theobj as alias
dim anobj as object
dim theTab as string
dim wdth,hght as float
set coordsys layout units "in"
�
theTab = windowinfo(layid,WIN_INFO_TABLE)
theobj = theTab+".obj"
�
fetch rec rid from theTab
anobj = theobj
if objectinfo(theobj,OBJ_INFO_TYPE) = obj_type_text then
�� if centerx <> -1 then
����� wdth =
objectgeography(anobj,OBJ_geo_maxx)-objectgeography(anobj,OBJ_geo_minx)
����� alter object anobj geography OBJ_geo_minx, (centerx-(wdth/2))
����� update theTab set obj = anobj where rowid = rid
�� end if
�� if centery <> -1 then
����� hght =
objectgeography(anobj,OBJ_geo_maxy)-objectgeography(anobj,OBJ_geo_miny)
����� alter object anobj geography OBJ_geo_miny, (centery-(hght/2))
����� update theTab set obj = anobj where rowid = rid
�� end if
end if
�
end sub
�
�
Sincerely,
John C. Hollingsworth
Director of GIS Programming
The Buxton Company
[EMAIL PROTECTED]
-----Original Message-----
From: Daniel Mack [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 18, 1999 5:50 PM
To: [EMAIL PROTECTED]
Subject: MI centering text in a layout
Hi all,
�
Before I attempt to use a Windows API function, does anyone know how to
center a text object in a layout window using MapBasic. The "create text"
statement allows the placement
point to be only in the upper left corner of the text object. I have tried
to use objectGeography function to calculate the extents of the text object,
but it gives incorrect results. Next, I tried to calculate the length of the
string based on the number of characters, but failed due to the variable
character size of Windows fonts.�
�
Thanks to anyone who can help.
�
Daniel Mack
Cave Creek Systems
Box 641 Nelson, B.C. V1L 5R4
(250)352-3085
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]