TH-Soft wrote:
EnvelopeExcursion wrote:
What's the desired scenario at this point with the above? That row should be orange, from the top of the page to whatever length I specify.
You set orange as the background colour for text in that row, but not as the background colour for the row.
Set "Row.Shading" instead of "Row.Format.Shading" to change the colour of the row. Maybe try yellow to see the difference.
Now THIS was useful to know! Row.Format.Shading and Row.Shading. I'm a little unsure why we can set Row.Format.Shading for formatting added text, when the formatting can just be done on the text itself that we're adding, via a paragraph, etc. However, that doesn't particular matter right now. More importantly, thanks! After observing the result of setting Row.Shading to orange instead of Row.Format.Shading, I could see that the height of the row was in fact changing. This meant that it turned out my code WAS pretty much working!
However, for the benefit of anyone seeking to centre text on a page both vertically and horizontally, they can do the following (this has none of the unrelated fluff I had in the code in my previous post):
Code:
MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
MigraDoc.DocumentObjectModel.Section section = document.AddSection();
MigraDoc.DocumentObjectModel.Shapes.TextFrame titleFrame = section.AddTextFrame();
titleFrame.RelativeHorizontal = MigraDoc.DocumentObjectModel.Shapes.RelativeHorizontal.Margin;
titleFrame.RelativeVertical = MigraDoc.DocumentObjectModel.Shapes.RelativeVertical.Margin;
//titleFrame.FillFormat.Color = MigraDoc.DocumentObjectModel.Colors.Blue;
titleFrame.Width = document.DefaultPageSetup.PageWidth - (document.DefaultPageSetup.LeftMargin + document.DefaultPageSetup.RightMargin);
titleFrame.Height = document.DefaultPageSetup.PageHeight - (document.DefaultPageSetup.TopMargin + document.DefaultPageSetup.BottomMargin);
MigraDoc.DocumentObjectModel.Tables.Table table = titleFrame.AddTable();
table.Rows.LeftIndent = MigraDoc.DocumentObjectModel.Unit.Zero; //If this is not specified, for some reason the table appears to be negatively indented to the left, meaning it sits slightly outside of the text frame.
table.Format.Alignment = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center;
MigraDoc.DocumentObjectModel.Tables.Column column = table.AddColumn();
//column.Format.Shading.Color = MigraDoc.DocumentObjectModel.Colors.Green;
column.Width = document.DefaultPageSetup.PageWidth - (document.DefaultPageSetup.LeftMargin + document.DefaultPageSetup.RightMargin);
MigraDoc.DocumentObjectModel.Tables.Row row = table.AddRow();
row.HeightRule = MigraDoc.DocumentObjectModel.Tables.RowHeightRule.Exactly;
row.Height = document.DefaultPageSetup.PageHeight - (document.DefaultPageSetup.TopMargin + document.DefaultPageSetup.BottomMargin);
//row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.Orange;
row.VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;
MigraDoc.DocumentObjectModel.Paragraph coverParagraph = row[0].AddParagraph();
coverParagraph.AddFormattedText("TEST_TITLE");
//coverParagraph.AddFormattedText("TEST_TITLETEST TITLE TEST TITLE TEST TEST TEST TEST TEST TEST TEST TESTTESTTESTTESTTESTTEST_TITLETEST TITLE TEST TITLE TEST TEST TEST TEST TEST TEST TEST TESTTESTTESTTESTTESTTEST_TITLETEST TITLE TEST TITLE TEST TEST TEST TEST TEST TEST TEST TESTTESTTESTTESTTESTTEST_TITLETEST TITLE TEST TITLE TEST TEST TEST TEST TEST TEST TEST TESTTESTTESTTESTTESTTEST_TITLETEST TITLE TEST TITLE TEST TEST TEST TEST TEST TEST TEST TESTTESTTESTTESTTEST");
I've left the commented out colour-setting lines so that if anyone using this code wants to check out the different areas, they'll be able to see, visually, that everything seems to be working.
For historical purposes, if you did uncomment those colour lines, you shouldn't see any blue. You should only see an orange box, with a green box in the middle around your text. There's a slight gap between the left and right edges of the green box and the edges of the orange box.
I've attached an image to show this:
Attachment:
HorizontallyAndVerticallyAlignedText.png [ 27.47 KiB | Viewed 11158 times ]
The final line with the longer string being passed to AddFormattedText() is left in to demonstrate that the centre area expands correctly.
I hope this helps anyone else trying to do something like this.