/// <summary>
    /// Add a new string to the current page
    /// </summary>
    /// <param name="text">The string to print</param>
    /// <param name="align">Optional alignment of the string</param>
    public void DrawString(string text, System.Windows.TextAlignment align = System.Windows.TextAlignment.Left)
    {
        // add string to document
        using (Graphics g = Graphics.FromImage(Pages[CurrentPage - 1])) {
            g.CompositingQuality = CompositingQuality.HighQuality;
            // get linespacing and adjust by user specified linespacing
            int iLineSpacing = (Int32)(g.MeasureString("X", Font).Height *(float)((float)LineSpacing / (float)100));
            switch (align)
            {
            case System.Windows.TextAlignment.Left:
            case System.Windows.TextAlignment.Justify:
                g.DrawString(text, Font, new SolidBrush(ForeColor), new PointF(X, Y));
                break;

            case System.Windows.TextAlignment.Right:
                g.DrawString(text, Font, new SolidBrush(ForeColor), new PointF(Pages[CurrentPage - 1].Width - g.MeasureString(text, Font).Width, Y));
                break;

            case System.Windows.TextAlignment.Center:
                g.DrawString(text, Font, new SolidBrush(ForeColor), new PointF((Pages[CurrentPage - 1].Width + g.MeasureString(text, Font).Width) / 2, Y));
                break;
            }
            Y += iLineSpacing;
            if (Y + iLineSpacing > Pages[CurrentPage - 1].Height)
            {
                NewPage();
            }
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Ensures that the presentation core DLL loaded.
        /// </summary>
        /// <returns></returns>
        public static string EnsurePresentationCoreLoaded()
        {
            // Problem: here maybe the PresentationCore is not referenced in this assembly, because it was up to now not needed
            // Result: the reflection subsystem will skip this assembly when searching for user controls, because it thinks that we have no dependency
            // on PresentationCore and hence no user controls can exist in this assembly
            // Solution: make sure that the presentation core is referenced, by referencing an arbitrary type in it
            var    alignment = new System.Windows.TextAlignment();
            string t         = alignment.ToString();

            return(t);
        }
 public static void SetTextAlignment(System.Windows.DependencyObject element, System.Windows.TextAlignment value)
 {
 }