Solved

C# Turn off printing message when using printForm

Posted on 2010-09-15
2
793 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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