Solved

C# Turn off printing message when using printForm

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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