private void PrintObjectData(User Node, float x, ref float y, float PrintWidth, Font PrintFont, float LineHeight) { PH.DrawText("Nazwisko i imię: ", PrintFont, x, y, PrintWidth, LineHeight, StringAlignment.Near, Brushes.Black, false, false); var Indent = PH.G.MeasureString("Nazwisko i imię: ", PrintFont).Width; PH.DrawText(Node.Name, new Font(PrintFont, FontStyle.Bold), x + Indent, y, PrintWidth - Indent, LineHeight, 0, Brushes.Black, false, false); y += LineHeight; PH.DrawText("Rola: ", PrintFont, x, y, PrintWidth, LineHeight, 0, Brushes.Black, false, false); Indent = PH.G.MeasureString("Rola: ", PrintFont).Width; PH.DrawText(Node.Role.ToString(), new Font(PrintFont, FontStyle.Bold), x + Indent, y, PrintWidth - Indent, LineHeight, 0, Brushes.Black, false, false); Indent += PH.G.MeasureString(Node.Role.ToString(), new Font(PrintFont, FontStyle.Bold)).Width; Indent += 20; PH.DrawText("Status: ", PrintFont, x + Indent, y, PrintWidth - Indent, LineHeight, 0, Brushes.Black, false, false); Indent += PH.G.MeasureString("Status: ", PrintFont).Width; PH.DrawText(Node.Status.ToString(), new Font(PrintFont, FontStyle.Bold), x + Indent, y, PrintWidth - Indent, LineHeight, 0, Brushes.Black, false, false); y += LineHeight * 2; PH.DrawText("Login: "******"Login: "******"Hasło: ", PrintFont, x + Indent, y, PrintWidth - Indent, LineHeight, 0, Brushes.Black, false, false); Indent += PH.G.MeasureString("Hasło: ", PrintFont).Width; PH.DrawText(Node.Password.ToString(), new Font(PrintFont, FontStyle.Bold), x + Indent, y, PrintWidth - Indent, LineHeight, 0, Brushes.Black, false, false); PH.DrawLine(x, y + LineHeight * 1.5f, x + PrintWidth, y + LineHeight * 1.5f); y += LineHeight * 2; }
private void doc_PrintPage(object sender, PrintPageEventArgs e) { #region -------------------------- Print variables definitions ----------------------- PH.G = e.Graphics; PrintDocument Doc = (PrintDocument)sender; float x = PH.IsPreview ? UserSession.User.Settings.LeftMargin : UserSession.User.Settings.LeftMargin - e.PageSettings.PrintableArea.Left; float y = PH.IsPreview ? UserSession.User.Settings.TopMargin : UserSession.User.Settings.TopMargin - e.PageSettings.PrintableArea.Top; float y0 = y; Font TextFont = UserSession.User.Settings.TextFont; Font HeaderFont = UserSession.User.Settings.HeaderFont; float LineHeight = TextFont.GetHeight(e.Graphics); float HeaderLineHeight = HeaderFont.GetHeight(e.Graphics); int PrintWidth = e.MarginBounds.Width; int PrintHeight = e.MarginBounds.Bottom; //int ColOffset = (PrintWidth + (int)x) * -1; #endregion PH.PageNumber += 1; #region --------------------------- Document header and footer ----------------------- PH.DrawHeader(x, y, PrintWidth); PH.DrawFooter(x, PrintHeight, PrintWidth); PH.DrawPageNumber("- " + PH.PageNumber.ToString() + " -", x, PrintHeight, PrintWidth, PageNumberLocation.Footer); #endregion #region ------------------------------ Report header ----------------------------------- if (PH.PageNumber == 1) { y += LineHeight; PH.DrawText(PH.ReportHeader[0], HeaderFont, x, y, PrintWidth, HeaderLineHeight, StringAlignment.Center, Brushes.Black, false); y += HeaderLineHeight * 2; } #endregion #region ------------------------------- Column Settings -------------------------- List <TableCellWithAlignment> Kolumna = new List <TableCellWithAlignment>(); foreach (OLVColumn Col in olvObsada.AllColumns.Where(c => c.AspectName != "ID")) { var Align = StringAlignment.Near; Enum.TryParse <StringAlignment>(Col.TextAlign.ToString(), out Align); Kolumna.Add(new TableCellWithAlignment { Name = Col.AspectName, Label = Col.Text, Size = Col.Width, Alignment = Align }); } int SpaceWidth = PrintWidth - Kolumna.Sum(K => K.Size); int Space = SpaceWidth / Kolumna.Count; foreach (var col in Kolumna) { col.Size += Space; } #endregion #region ------------------------------- Table header -------------------------------- float MultiplyLine = 3; int ColOffset = 0; if (PH.PageNumber == 1) { for (int i = 0; i < Kolumna.Count(); i++) { PH.DrawText(Kolumna[i].Label, new Font(TextFont, FontStyle.Bold), x + ColOffset, y, Kolumna[i].Size, LineHeight * MultiplyLine, StringAlignment.Center, Brushes.Black); ColOffset += Kolumna[i].Size; } y += LineHeight * MultiplyLine; } #endregion y += LineHeight; #region ---------------------------- Document body ----------------------------------- while (y + HeaderLineHeight * 2 < PrintHeight && PH.Offset[0] < olvObsada.Groups.Count) { if (PH.Offset[1] == 0) { PH.DrawText(olvObsada.Groups[PH.Offset[0]].ToString(), HeaderFont, x, y, PrintWidth, HeaderLineHeight, 0, Brushes.Black, false); y += HeaderLineHeight; PH.DrawLine(x, y, x + PrintWidth, y); y += HeaderLineHeight; } while (y + LineHeight < PrintHeight && PH.Offset[1] < olvObsada.Groups[PH.Offset[0]].Items.Count) { PrintObjectData(olvObsada.OLVGroups[PH.Offset[0]].Items[PH.Offset[1]].RowObject as SubjectSchemeModel, x, ref y, Kolumna, TextFont, LineHeight); PH.Offset[1]++; } if (PH.Offset[1] < olvObsada.OLVGroups[PH.Offset[0]].Items.Count) { PH.PrintNextPage(Doc, e); } else { y += LineHeight; PH.Offset[1] = 0; PH.Offset[0]++; } } if (PH.Offset[0] < olvObsada.Groups.Count) { PH.PrintNextPage(Doc, e); } #endregion }
private void tlvAnaliza_PrintPage(object sender, PrintPageEventArgs e) { #region -------------------------- Print variables definitions ----------------------- PH.G = e.Graphics; PrintDocument Doc = (PrintDocument)sender; float x = IsPreview ? UserSession.User.Settings.LeftMargin : UserSession.User.Settings.LeftMargin - e.PageSettings.PrintableArea.Left; float y = IsPreview ? UserSession.User.Settings.TopMargin : UserSession.User.Settings.TopMargin - e.PageSettings.PrintableArea.Top; Font TextFont = UserSession.User.Settings.TextFont; Font SubHeaderFont = UserSession.User.Settings.SubHeaderFont; Font HeaderFont = UserSession.User.Settings.HeaderFont; float LineHeight = TextFont.GetHeight(e.Graphics); float SubHeaderLineHeight = SubHeaderFont.GetHeight(e.Graphics); float HeaderLineHeight = HeaderFont.GetHeight(e.Graphics); int PrintWidth = e.MarginBounds.Width; int PrintHeight = e.MarginBounds.Bottom; #endregion PageNumber += 1; #region --------------------------- Document header and footer ----------------------- PH.DrawHeader(x, y, PrintWidth); PH.DrawFooter(x, PrintHeight, PrintWidth); PH.DrawPageNumber("- " + PageNumber.ToString() + " -", x, PrintHeight, PrintWidth, PageNumberLocation.Footer); #endregion #region ------------------------------ Report header ----------------------------------- if (PageNumber == 1) { y += LineHeight; PH.DrawText(ReportHeader[0], HeaderFont, x, y, PrintWidth, HeaderLineHeight, StringAlignment.Center, Brushes.Black, false); y += HeaderLineHeight * 2; } #endregion #region ------------------------------- Column Settings -------------------------- List <TableCell> Kolumna = new List <TableCell>(); foreach (OLVColumn Col in tlvStudent.Columns) { Kolumna.Add(new TableCell { Name = Col.AspectName, Label = Col.Text, Size = Col.Width - 20 }); } int FirstColWidth = PrintWidth - Kolumna.Where(K => K.Name != "Label").Sum(K => K.Size); if (FirstColWidth > 0) { Kolumna.Where(K => K.Name == "Label").First().Size = FirstColWidth; } #endregion #region ------------------------------- Table header -------------------------------- float MultiplyLine = 3; int ColOffset = 0; if (PageNumber == 1) { for (int i = 0; i < Kolumna.Count(); i++) { PH.DrawText(Kolumna[i].Label, new Font(TextFont, FontStyle.Bold), x + ColOffset, y, Kolumna[i].Size, LineHeight * MultiplyLine, StringAlignment.Center, Brushes.Black); ColOffset += Kolumna[i].Size; } y += LineHeight * MultiplyLine; } ColOffset = 0; for (int i = 0; i < Kolumna.Count(); i++) { PH.DrawText((i + 1).ToString(), new Font(TextFont, FontStyle.Bold | FontStyle.Italic), x + ColOffset, y, Kolumna[i].Size, LineHeight, StringAlignment.Center, Brushes.Black); ColOffset += Kolumna[i].Size; } y += LineHeight * 1.5F; #endregion #region ------------------------ Table body -------------------------------- int index = 0; int Indent = 0; bool Shade = false; Font PrintFont = null; var ListItems = tlvStudent.FilteredObjects.Cast <ScoreBranch>(); while (y + LineHeight * 2 < PrintHeight && Offset[0] < ListItems.Count()) { var ListItem = ListItems.ToArray()[Offset[0]]; y += LineHeight * 0.5f; PrintFont = new Font(TextFont, FontStyle.Bold); switch (ListItem.Level) { case 0: Indent = 0; MultiplyLine = 2; Shade = true; index = 0; break; case 1: Indent = 20; MultiplyLine = 2; Shade = false; index = 0; break; case 2: Indent = 40; MultiplyLine = 1; Shade = false; PrintFont = TextFont; if (index > 0) { y -= LineHeight * 0.5f; } index++; break; } PrintModelObjectData(ListItem, x, ref y, Kolumna, PrintFont, LineHeight * MultiplyLine, Indent, Shade); Offset[0]++; } if (Offset[0] < ListItems.Count()) { PrintNextPage(Doc, e); } #endregion }
private void prnDoc_PrintPage(object sender, PrintPageEventArgs e) { #region -------------------------- Print variables definitions ----------------------- PH.G = e.Graphics; PrintDocument Doc = (PrintDocument)sender; float x = IsPreview ? UserSession.User.Settings.LeftMargin : UserSession.User.Settings.LeftMargin - e.PageSettings.PrintableArea.Left; float y = IsPreview ? UserSession.User.Settings.TopMargin : UserSession.User.Settings.TopMargin - e.PageSettings.PrintableArea.Top; Font TextFont = UserSession.User.Settings.TextFont; Font SubHeaderFont = UserSession.User.Settings.SubHeaderFont; Font HeaderFont = UserSession.User.Settings.HeaderFont; float LineHeight = TextFont.GetHeight(e.Graphics); float SubHeaderLineHeight = SubHeaderFont.GetHeight(e.Graphics); float HeaderLineHeight = HeaderFont.GetHeight(e.Graphics); int PrintWidth = e.MarginBounds.Width; int PrintHeight = e.MarginBounds.Bottom; #endregion PageNumber += 1; #region --------------------------- Document header and footer ----------------------- PH.DrawHeader(x, y, PrintWidth); PH.DrawFooter(x, PrintHeight, PrintWidth); PH.DrawPageNumber("- " + PageNumber.ToString() + " -", x, PrintHeight, PrintWidth, PageNumberLocation.Footer); #endregion #region ------------------------------ Report header ----------------------------------- if (PageNumber == 1) { y += LineHeight; PH.DrawText(ReportHeader[0], HeaderFont, x, y, PrintWidth, HeaderLineHeight, StringAlignment.Center, Brushes.Black, false); y += HeaderLineHeight * 2; } #endregion #region ------------------------------- Column Settings -------------------------- List <TableCell> Kolumna = new List <TableCell>(); foreach (OLVColumn Col in olvStudent.Columns) { Kolumna.Add(new TableCell { Name = Col.AspectName, Label = Col.Text, Size = Col.Width }); } int SpaceWidth = PrintWidth - Kolumna.Sum(K => K.Size); int Space = SpaceWidth / Kolumna.Count; foreach (var col in Kolumna) { col.Size += Space; } #endregion #region ------------------------------- Table header -------------------------------- float MultiplyLine = 2; int ColOffset = 0; if (PageNumber == 1) { for (int i = 0; i < Kolumna.Count(); i++) { PH.DrawText(Kolumna[i].Label, new Font(TextFont, FontStyle.Bold), x + ColOffset, y, Kolumna[i].Size, LineHeight * MultiplyLine, StringAlignment.Center, Brushes.Black); ColOffset += Kolumna[i].Size; } y += LineHeight * MultiplyLine; } #endregion y += LineHeight; #region ------------------------ Table body -------------------------------- MultiplyLine = 2.2f; while (y + LineHeight * MultiplyLine < PrintHeight && Offset[0] < olvStudent.Groups.Count) { if (Offset[1] == 0) { PH.DrawText(olvStudent.Groups[Offset[0]].Header, SubHeaderFont, x, y, PrintWidth, SubHeaderLineHeight, 0, Brushes.Black, false); y += LineHeight * 1.2f; PH.DrawLine(x, y, x + PrintWidth, y); y += LineHeight * 0.5f; } MultiplyLine = 1; while (y + LineHeight * MultiplyLine < PrintHeight && Offset[1] < olvStudent.Groups[Offset[0]].Items.Count) { int colSize = 0; for (int i = 0; i < Kolumna.Count; i++) { PH.DrawText(olvStudent.Groups[Offset[0]].Items[Offset[1]].SubItems[i].Text, TextFont, x + colSize, y, Kolumna[i].Size, LineHeight * MultiplyLine, i == 1 ? StringAlignment.Center : StringAlignment.Near, Brushes.Black, false); colSize += Kolumna[i].Size; } y += LineHeight; Offset[1] += 1; } y += LineHeight; if (Offset[1] < olvStudent.Groups[Offset[0]].Items.Count) { PrintNextPage(Doc, e); return; } else { Offset[1] = 0; Offset[0] += 1; } } if (Offset[0] < olvStudent.Groups.Count) { PrintNextPage(Doc, e); } #endregion }