Solved

C# Turn off printing message when using printForm

Posted on 2010-09-15
2
789 Views
Last Modified: 2013-12-16
Hi

I'm new to C#

I'm looping through my windows forms using printform from the visual basic powerpack (even though coded in c#) to print them.  I'm getting a message pop up for each form saying "print page 1 of ..."  I'd like to stop this message from popping up and then show my own message after all have been printed.

I tried setting PrintController = new StandardPrintController();  but this only works for printDocument and not printForm by the looks of it.  

Is there any turning this message off when using printform?

Thanks in advance!
0
Comment
Question by:greep
2 Comments
 
LVL 1

Accepted Solution

by:
Harvey earned 500 total points
ID: 33689066
I just opened up a reflector and checked.  Interally, PrintForm is also using PrintDocument.  Unfortunately, the PrintDocument is a private variable.  I tired setting it using reflection.  Please check the attached code.  It works if you are printing to a printer.  If you are printing to a preview, it still shows the dialog.  It sounds like the PrintPreviewDialog also has its own PrintController.  You can open up the reflector and check.
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Reflection;

using Microsoft.VisualBasic.PowerPacks.Printing;

using System.Drawing.Printing;



namespace PrintFormTest

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }



        private void button1_Click(object sender, EventArgs e)

        {

            printForm1.PrintAction = System.Drawing.Printing.PrintAction.PrintToPrinter;



            Type t = typeof(PrintForm);

            FieldInfo fi = t.GetField("_m_PrintDoc", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);

            PrintDocument pd = fi.GetValue(printForm1) as PrintDocument;

            pd.PrintController = new StandardPrintController();



            printForm1.Print();

        }



    }

}

Open in new window

0
 

Author Closing Comment

by:greep
ID: 33689650
That does the job perfectly!  Much appreciated!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now