?
Solved

C# Turn off printing message when using printForm

Posted on 2010-09-15
2
Medium Priority
?
802 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 2000 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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