|
Hi,
I was adding a print preview dialog to an app, but when doing some testings (I had never worked with previews) something happens that the preview dialog displays nothing besides a blank page, the printer is working fine. The code is:
using System; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; public class PruebaPrint { private static string cadena; private static PrintDocument pd; internal static PrintPreviewDialog vpd = new PrintPreviewDialog();
public static void initDoc(string name) { pd = new PrintDocument(); pd.DocumentName = name; pd.PrinterSettings.Collate = true; pd.PrintPage += new PrintPageEventHandler(OnPrintPage); }
public static bool Imprimir(string str, string name) { cadena = str; initDoc(name); PrintDialog dlg = new PrintDialog(); dlg.Document=pd; DialogResult resultado = dlg.ShowDialog(); if (resultado == DialogResult.OK) pd.Print(); return true; }
private static void OnPrintPage (object obj, PrintPageEventArgs ppea) { Graphics graf = ppea.Graphics; Font font = new Font("Tahoma", 12); graf.DrawString(cadena, font, Brushes.Black, graf.VisibleClipBounds.Width/2, graf.VisibleClipBounds.Height/2); vpd.Text="lo que sea"; }
public static bool VistaPrevia (string str, string name) { cadena = str; initDoc(name); vpd.ClientSize = new System.Drawing.Size(600, 400); vpd.Location = new System.Drawing.Point(10,10); vpd.Document = pd; vpd.ShowDialog(); return true; }
}
I hope someone can help me.
Note: My Framework (and SDK) instalation is in spanish the same as my windows xp, I belive this is not important, but I just can't figure the reason of the problem. |