Solved

C# Turn off printing message when using printForm

Posted on 2010-09-15
2
790 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

17 Experts available now in Live!

Get 1:1 Help Now