Windows Develop Bookmark and Share   
 index > Windows Forms General > PrintPreviewDialog has no data
 

PrintPreviewDialog has no data

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.
MigrationUser 1  Tuesday, October 12, 2004 6:32 PM
The problem is solved, doing another testing with "PageBounds" the preview dialog works fine. The problem is due to a bug with â€śVisibleClipBoundsâ€?

I apologize because some of you have discussed the issue before and I didn’t noted it (you can read the post by Neville â€śMisadventures in Printingâ€?.
MigrationUser 1  Thursday, October 14, 2004 1:40 AM

You can use google to search for other answers

Custom Search

More Threads

• The datagrid combobox validation
• Custom Tab Control (maybe docking)
• c# memory problem
• DsoFramer 1.3 timeout bug - Unable to save document
• Keys Enumeration for ">" or "." at letter's part
• Combobox items inaccessible in code
• Capture Up, Down button from DateTimePicker
• Adding Dictionary type list to CheckedListBox
• ListView "Tile" View Issue: VS2005 / .NET 2.0
• Resources