set the footer in place - c#

setting the footer..
in the above screen the footer is displayed after new member report and reporting period but i dont want like this
I'm working on windows application using C#.
I have generated the "Report" using Ms chart control. While printing and exporting into XPS format, Header and Footer are appearing its fine .
But i want the Footer will be displayed at the bottom of the report at present it was appearing just after the header, I want to add this Footer at the bottom using C#. So user can print page with Header and Footer. How to do this.
can any one have idea about this ..
Many thanks....
this is my code
Title maintitle = kpiChartControl.Titles.Add("New Members Report" + Environment.NewLine);
maintitle.Alignment = ContentAlignment.TopLeft;
maintitle.Font = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold);
Title rangetitle = kpiChartControl.Titles.Add(string.Format("Report period from : {0} to {1}{2}", dStartDate.Value.ToString(xxx.dateFormat),
denddate.Value.ToString(xxxx.dateFormat), Environment.NewLine));
rangetitle.Alignment = ContentAlignment.TopLeft;
rangetitle.Font = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold);
Title footertitle = kpiChartControl.Titles.Add("--------------------------------------------------------" + Environment.NewLine);
footertitle.Alignment = ContentAlignment.BottomCenter;
Title gompanytitle = kpiChartControl.Titles.Add("xxxx");
gompanytitle.Alignment = ContentAlignment.BottomLeft;
gompanytitle.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Regular);
Title printedby = kpiChartControl.Titles.Add(string.Format("Printed By ("+text+") On :{0}", dt,Environment.NewLine));
printedby.Alignment = ContentAlignment.BottomRight;
printedby.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Regular);
kpiChartControl.Printing.Print(true);
kpiChartControl.Titles.Remove(maintitle);
kpiChartControl.Titles.Remove(rangetitle);
kpiChartControl.Titles.Remove(footertitle);
kpiChartControl.Titles.Remove(gompanytitle);
kpiChartControl.Titles.Remove(printedby);

The trick is to use the Docking property. So for all items that you wish to place below the graph, do the following
printedby.Docking = Docking.Bottom;
gompanytitle.Docking = Docking.Bottom;
footertitle.Docking = Docking.Bottom;

I'm kinda guessing here to be honest - but it seems to me that you need to be adding the footer in the XPS document, rather than as part of the chart. My guess is that the chart will always by displaying titles at the top.
This SO - about adding header/footer to an XPS - should help: add footer to FlowDocumentsdocuments, both Sauron's and Vikram's answers there should provide the information you need.

Related

marking text in richtexbox

I have a problem, I want to somehow mark text in my richtextbox. I tried to change font between adding content to richtextbox (below is code, but it works only on first text).
Font bolded = new Font("Georgia", 14, FontStyle.Bold);
Font normal = new Font("Georgia", 14, FontStyle.Regular);
logBox.Font = bolded;
logBox.Text += "Number of elements: " + dir.GetLength(0) +
Environment.NewLine + Environment.NewLine;
logBox.Font = normal;
So, can I change anything to mark my text (bolding it would be the best), and If I can't do it on richtextbox is there any other way? (my app writes a lot to this item)
Edit: I'm targetting Windows Forms Application.

Using iTextSharp to construct header on multiple pdf pages

I'm generating a PDF file based on a record selected in my datagridview. It will consist of 3-5 pages. I created a table with 2 columns to represent my header. the first cell is left aligned and the 2nd cell is right aligned. I want this same inforamtion displayed on all pages.
After doing some googling, I saw a header.WriteSelectedRows() property which is supposed to help with that? One example was :
header.WriteSelectedRows(0, -1, doc.PageSize.GetLeft(5), doc.PageSize.GetTop(5), wri.DirectContent);
2nd was:
header.WriteSelectedRows(0, -1, doc.LeftMargin, doc.PageSize.Height - 36, wri.DirectContent);
However both resulted in just the first page having the table/header. Any ideas on what I need to fix? Thanks!
Code:
PdfPTable header = new PdfPTable(2);
header.HorizontalAlignment = Element.ALIGN_LEFT;
header.TotalWidth = doc.PageSize.Width - 20f;
header.LockedWidth = true;
Phrase cell1 = new Phrase(signal.ProformaType);
Phrase cell2 = new Phrase("text" + Environment.NewLine + "text"
+ Environment.NewLine + signal.Signal);
PdfPCell c1 = new PdfPCell(cell1);
c1.Border = iTextSharp.text.Rectangle.NO_BORDER;
c1.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
c1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
header.AddCell(c1);
PdfPCell c2 = new PdfPCell(cell2);
c2.Border = iTextSharp.text.Rectangle.NO_BORDER;
c2.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
c2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
header.AddCell(c2);
header.WriteSelectedRows(0, -1, doc.LeftMargin, doc.PageSize.Height - 36, wri.DirectContent);
The PdfPTable is added to the first page only because you are adding it to the first page only. If you want to add it to every page that is created by iText, you shouldn't add the PdfPTable where you are adding it now.
Instead you should add it in the OnEndPage() method of a page event. This is explained in answers to questions such as:
How can I add Header and footer in pdf using iText in java?
how to add an image to my header in iText generated PDF?
How to handle the case in wich an iText\iTextSharp table is splitted in two pages?
...
In other words, you need to create your own implementation of the PdfPageEvent interface. The best way is to extend the PdfPageEventHelper class:
public class MyPageHeader : PdfPageEventHelper
{
PdfPTable header = ... // define header table here
public override void OnEndPage(PdfWriter writer, Document document)
{
header.WriteSelectedRows(0, -1, document.Left, document.Top, writer.DirectContent);
}
}
To make this work, you need to declare this page event before opening the Document:
PdfWriter pdfWriter = PdfWriter.GetInstance(document, pdfFileStream);
pdfWriter.PageEvent = new MyPageHeader();
document.Open();
Now, every time a new page is created, the header will be added automatically.
You may want to adapt document.Left and document.Top in the code above, because right now, it will add the table in the upper-right corner of each page, you may want to use document.Left + 36 and document.Top - 5 or something like that.
Also: make sure that there is sufficient room for the header, otherwise your header will overlap with the content you are adding straight to the Document using document.Add(). You can change the margins in the constructor of the Document class.

Render CheckBox to Image for Tile

I want to display one or more CheckBoxes on a tile in my Windows Phone app. This works already for TextBlocks, but with a CheckBox it shows only the Text of the CheckBox and not the Checkmark itself.
This is a sample of my code:
public void CreateTile()
{
StackPanel panel = new StackPanel();
panel.VerticalAlignment = VerticalAlignment.Top;
panel.Margin = new Thickness(7.0, 7.0, 7.0, 0);
panel.Width = 336;
panel.Height = 336;
panel.Orientation = Orientation.Vertical;
// Create and add a CheckBox for each task
foreach (var task in _tasks)
{
TextBlock textBlock = new TextBlock();
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Style = App.Current.Resources["PhoneTextLargeStyle"] as Style;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.Text = task.Text;
CheckBox checkBox = new CheckBox();
checkBox.IsChecked = task.IsDone;
checkBox.Content = textBlock;
panel.Children.Add(checkBox);
}
Grid layoutRoot = new Grid();
layoutRoot.Background = new SolidColorBrush(Colors.Blue);
layoutRoot.Width = 336;
layoutRoot.Height = 336;
layoutRoot.Children.Add(panel);
layoutRoot.Measure(new Size(336, 336));
layoutRoot.Arrange(new Rect(0, 0, 336, 336));
layoutRoot.UpdateLayout();
// Render grid into bitmap
WriteableBitmap bitmap = new WriteableBitmap(336, 336);
bitmap.Render(layoutRoot, null);
bitmap.Invalidate();
// Save background image for tile to isolated storage
Uri backgroundImage = TileHelper.SaveTileImage(bitmap);
}
If I create a tile with a background image created by the method above, the tile will look like this:
As you can see the text is displayed but there is no checkmark/square before the text.
I personally like to use Segoe UI Symbol as the Font Family in such situations. This gives me the flexibility to use Text and Symbols together while not messing around too much with code / images. SUS has great modern icons (or characters if you may call them) that are very much Metroish, I'd say.
Just open up Charmap (Win + R and type in charmap) and in the Font Select -> Segoe UI Symbol. Now you can select any character you like and paste into Visual Studio Editor itself. Yes, it works!
The symbol may not display properly in the Editor itself but it will at Runtime
Here are some suggestions:
Here are the corresponding characters:
☑

✅

Don't worry about them not looking right HERE. They should when you follow the above steps.
You can always "hack" it by using images of checkbox controls. Did you try to show created control in UI? i.e. adding it to page? Just to see if your code is executed correctly.
Or another solution would be to use check mark character - http://www.fileformat.info/info/unicode/char/2713/index.htm
I'll try to replicate this problem in my test app since it is strange that it does not work.

Dynamically Create Checkbox With Scrolling

I'm trying to build a form application in Visual Studio 2010 using C#.
The program will be reading a excel file that contains a list of filenames, and will dynamically generate textbox for each filename.
Below is my code, just for clarification. I wanted to make the label a link to the file, that's why I didn't use checkboxes[i].Text = filename
CheckBox[] checkboxes = new CheckBox[fileCount];
Label[] labels = new Label[fileCount];
for (int i = 0; i < fileCount; i++ )
{
//creating a checkbox
checkboxes[i] = new CheckBox();
checkboxes[i].Location = new Point(360, (145 + i * 30));
checkboxes[i].Name = String.Format("checkbox{0}", i.ToString());
this.Controls.Add(checkboxes[i]);
//creating filename label
labels[i] = new Label();
labels[i].Location = new Point(20, (150 + i * 30));
labels[i].Text = existingFiles[i];
labels[i].Width = 330;
this.Controls.Add(labels[i]);
}
Say if fileCount equals to 100, it will make the form really big/long and won't be able to fit properly on most monitors.
Is there a way to make all dynamically generated checkboxes and labels all grouped in a area and just have the user be able to scroll? Something like a panel with scrolling? I don't know if there's anything like that.
I thought about using CheckedListBox, but doing that way I won't be able to make the filename a link. I want the user be able to click on the label and the file will be opened automatically, instead of selecting it.
Any help is appreciated!
Most controls have the AutoScroll property. Set this to true, and the control will automatically add a scrollbar when necessary. You can use the Panel control and add all of your links/checkboxes to that (if you don't want your whole form to scroll).

PrintDocument (FixedDoc) WordWrapping?

So I am printing out some text from a textbox, which has wordwrapping enabled, but when I print out the document, the string that should be wordwrapped does not, and cuts offs on the page. I'd like to simply enable word wrapping for my printed document. Also is there a way to set the margins for the printed document, some of the text gets cut off from both the top and left margins. Thanks! Code attached below.
FixedDocument document = new FixedDocument();
document.DocumentPaginator.PageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
FixedPage page1 = new FixedPage();
page1.Width = document.DocumentPaginator.PageSize.Width;
page1.Height = document.DocumentPaginator.PageSize.Height;
MessageBox.Show(page1.Height.ToString() + page1.Width);
GridType.Children.Remove(Textbox);
page1.Children.Add(Textbox);
PageContent page1Content = new PageContent();
((IAddChild)page1Content).AddChild(page1);
document.Pages.Add(page1Content);
printDlg.PrintDocument(document.DocumentPaginator, "My first document");
page1.Children.Remove(Textbox);
GridType.Children.Add(Textbox);
Your textbox setting won't applied in PrintDoc .. you must recalculate all in your printdoc printpage event

Categories

Resources