I need to add couple of text lines on the top of the page when print an UltraGrid. Also I need to show preview dialog before print . The print output should be something like this for example:
Number: 123456 Name: ABCD
Address: xxxxxxxx Zip: 12345
----------------------------------------------
| my UltraGrid data |
-----------------------------------------------
So I added UltraGridPrintDocument and UltraPrintPreviewDialog in my form. And I tried to use that "ultraGridPrintDocument.Header.TextLeft" property but it seems can only add one text line and also cannot be formatted to align those fields on the top. Here is my code snip:
ultraGridPrintDocument.Header.TextLeft = "Number...................";
ultraPrintPreviewDialog.Document = ultraGridPrintDocument;
ultraPrintPreviewDialog.ShowDialog(this);
So what is the right way to add text lines on top of the Grid and also make those text fields aligned? Should I put those text fields into another UltraGrid and add that on top of my data grid when print? Please provide some sample code if possible.
Thanks!
Hi,
The grid print operation creates it's own print job. So there's no way to add anything into the printout except by using the header and/or footer of the page. These will be repeated on each page, of course, so that might not be what you want.
If using the page header is okay, then you can use as many lines as you like by putting line breaks into your header text.
this.ultraGridPrintDocument1.Header.TextLeft = "Number: xxxxxx" + Environment.NewLine + "Address: xxxxxxx";
I am not sure what you mean by "cannot be formatted to align those fields on the top."
Thanks Mike. It seems to me using the header of the page is okay even it is repeated in each page. What I mean to "align the fields on the top" is to put those fields in column kind of alignment, something as this:
Number: 12345 Name: abcdefghijkl
Address: xxxxxxxxxxxxxxxxx Zip: 12345
I basically want "Number:...' and "Address:..." are aligned as first column and 'Name:..." and "Zip:..." are aligned as second column. And other fields are aligned as third column etc.. I figured out a way to do that by padding spaces on each field and then use the fixed width font such as "Courier New" for header to make that happen. Do you have any better way to do that?
Another question is since each line in the header might be very long, how to calculate which font size I should use to fit them in the width of the print page?