The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Center text

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
starman2049 Posted - 03/24/2010 : 6:46:30 PM
I have added text to a page programatically and I want to be able to have it centered in X how do I do this?

Origin Ver. and Service Release (Select Help-->About Origin): 8.1
Operating System: XP
5   L A T E S T    R E P L I E S    (Newest First)
Penn Posted - 04/06/2010 : 9:59:55 PM
Hi,

The unit of pixel maybe satisfy your requirement. So, the first thing is to set unit to be pixel, and then get the width value. You can try the following code.

void page_center_x()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
		return;
	
	GraphPage gp = gl.GetPage();
	if(!gp)
		return;	

	Tree tr1;
	tr1.Root.Dimension.Units.nVal = 3;  // pixel = 3
	if(0 == gp.UpdateThemeIDs(tr1.Root))
		gp.ApplyFormat(tr1, true, true);  // set unit to pixel

	Tree tr;
	tr = gp.GetFormat(FPB_ALL, FOB_ALL, true, true);  // get format tree of the graph page
	double dWidth = tr.Root.Dimension.Width.dVal;  // get the width of the graph page
	printf("x center=%f\n", dWidth/2);
	
	
	GraphObject go = gl.GraphObjects("TITLE_SAMPLING_RATE");
	go.Text = "sampleString";
	go.Left = dWidth*0.9 - go.Width/2;
}


Penn
OriginLab Technical Services
starman2049 Posted - 04/06/2010 : 1:41:09 PM
Penn, thank you.

When I run your code I get width in inches, but the GraphObject.Left expects device units (width is like 6000, I assume to be printer DPI * page width? So how do I get width in a way that I can align a GraphObject?

I want to do the following:

GraphObject go = gl.GraphObjects("TITLE_SAMPLING_RATE");
go.Text = sampleString;
go.Left = gp.SomePropertyToGetWidth*0.9 - go.Width/2;

That should make it look like the text is right-justified at 90% of the page width.

Thanks!
Penn Posted - 03/29/2010 : 03:49:50 AM
Hi,

You can activate your graph, then run the following function.

void page_center_x()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
		return;
	
	GraphPage gp = gl.GetPage();
	if(!gp)
		return;
	
	Tree tr;
	tr = gp.GetFormat(FPB_ALL, FOB_ALL, true, true);  // get format tree of the graph page
	//out_tree(tr);  // print this format tree
	
	double dWidth = tr.Root.Dimension.Width.dVal;  // get the width of the graph page
	printf("x center=%f\n", dWidth/2);
}

I hope it is what you want.

Penn
OriginLab Technical Services
starman2049 Posted - 03/26/2010 : 5:49:13 PM
I checked out the examples - thank you. In my case I am trying to put multiple charts on one page, it could be 1, 2, 3, 4, or more.

I am unable to figure out how to find the proper X of the center of the page, regardless of what layers/charts are present.

Does anyone know how to find the center X of the page?
Penn Posted - 03/24/2010 : 10:00:56 PM
Hi,

These examples can help.

Penn
OriginLab Technical Services

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000