.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Printing: Preview and Print from Your Windows Forms App with the .NET Printing Namespace

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Printing is an integral part of every complete Windows-based application. Providing robust printing capabilities in these applications has often proved to be a tedious chore. Now, printing from Windows Forms with the .NET Framework means you must adopt a document-centric approach, resulting in cleaner and more manageable code. While the System.Windows.Forms namespace provides seamless integration with all the standard print dialogs (such as Print Preview, Page Setup, and Print), the System.Drawing.Printing namespace offers numerous classes for extensibility and customization. These classes, and how they provide access to printing capabilities, are covered here. Other useful techniques, such as printing in the background to allow the user to continue other tasks, is also explained.

Alex Calvo

MSDN Magazine February 2003

View Complete Post

More Related Resource Links

InfoPath Print View in web based InfoPath forms not printing


Hi All,

I am using InfoPath 2007 web based forms along with SharePoint 2007. I have set print views in all forms with proper formatting. But when I try to print a form, print view is not printed instead current view of infopath is printed. This behavior is happening in InfoPath Web based forms however in InfoPath client based forms I am successfully able to print a form with print view.

Can any body help me how to solve this problem ? 

Printing with Windows Forms not properly centered?

Hi Guys,

I have run into an odd problem trying to do printing with Windows Forms. I needed to add printing to my own code (printing barcode labels), and when I was done my code worked great, except that stuff I had centered on my labels was not actually, well centered! It was always off to the right and down a bit.

So I decided to see what I might have done wrong, and put together a really simple Windows form printing sample program, that would just print something on the page and center it within the page bounds. When I print it on all the printers I have access to here at the office, it does not print correctly. I added code to the print page function to print a rectangle around the margin bounds, which are supposed to be 1" from each corner be default. When it prints out, you can clearly see that the margins are NOT printed in the right locations, yet the item centered on the page is perfectly centered within the margin bounds.

So it would seem I am doing something wrong, but in fact it turns out my code is correct, but something is NOT right with the way Windows Forms handles printing. The reason I say that, is I have since discovered that if I print the document to an Adobe PDF file, or a Microsoft XPS document, when I view the result it is 100% correct! More importantly, when I PRINT that file using Adobe Acrobat, or the Microsoft

Printing and Print Preview hangs on a large report


Using SQL Server 2008 R2 Cumlative Update #4 (build 10.50.1746)

A report that is 119 pages long hangs after page 113 in both the print preview and printing.

A different report that is 90 pages long hangs on page 60 in both the print preview and printing.

These reports worked fine before applying the cumulative update #4.

Bluetooth Printing Guide using Windows Mobile Pocket Pc

FieldSoftware Products printing products use the Bluetooth "Serial Port Profile" (SPP). Unfortunately, there is no standard method to find your Bluetooth printer and begin printing... each device contains a Bluetooth stack/driver that determines the steps. There are two main stacks currently available... one from Microsoft and one from WIDCOMM/Broadcom. Below are step-by-step instructions for printing with the Microsoft and WIDCOMM stacks. Note that these may change for different versions of the Bluetooth stacks or for different manufacturers. Consult the documentation for your device for specific details on your device.

Identifying your device''s Bluetooth stack: There is no sure steps to identify a Bluetooth stack on a device. Below are steps for identifying current WIDCOMM and Microsoft stacks at the time this page is published. Note that these may not identify earlier or later versions of the same BT stacks.

Windows Forms: .NET Framework 1.1 Provides Expanded Namespace, Security, and Language Support for Yo


With the much-anticipated release of the .NET Framework 1.1, developers are eager to know what's been added to their programming bag of tricks. In this article, the author focuses on new developments in Windows Forms, such as namespace additions, support for hosting managed controls in unmanaged clients, and designer support for C++ and J#. Integrated access to the Compact Framework and new mobile code security settings also make this release noteworthy. Along with these features, the author reviews the best ways to handle multiple versions of the common language runtime and highlights some potential pitfalls.

Chris Sells

MSDN Magazine March 2003

Infopath 2007 not printing footer in browser print view

I have added a footer to the print view of a browser enabled form and it is not printing when printing the form. The footer is relatively sinmple, however when I click on print view on the browser form and use print preview, I cannot see the footer at all. I have set bottom margins to auto, however I am using an image in my header and therefore have a section at the top of each page where my page top margin is set to 0 and the margins lie within the bounds of the section at .25". The footer that is not displaying in print preview in the form is as follows;"Quote Number: &{/my:myFields/my:sqnumber&} &b&pof&P&b &b &{/my:myFields/my:group28/my:sqdate&}Revision: &{xdFormatting:FormatString("/my:myFields/my:sqquoterevision","number","numDigits:0;negativeOrder:1;")&} &b Prepared For: &{/my:myFields/my:sqclientname&}"The page setup in IE listed page number and url info when using print preview and I have set them to none because my footer is in the form. Please help, this is frustrating!

Printing Landscape Report using the Print Control of the ASP.NET Report Viewer

I am using the ASP.NET Report Viewer 2010 web control in remote processing mode connected to a SQL Server Reporting Services 2008 R2 report server in Native Mode. I am viewing the report in IE8 and the print control within the report viewer is available. According to "Printing Reports from a Browser Using the Print Control" at http://msdn.microsoft.com/en-us/library/ms159237.aspx  "The Print dialog box and the default printer settings for width, height, and page orientation are determined by the report definition." In SQL Server Business Intelligence Development Studio I am using the “Report Properties” window accessed from the “Report” menu to set the Orientation to “Landscape”, the paper size to “Letter”, the Width to “11in”, and the Height to “8.5in” in the report definition. When viewing the report using the ASP.NET Report Viewer 2010 in IE8 and exportint to PDF, the report renders correctly in landscape orientation and the size both on screen and printed is as defined in the report definition. However, if I print it directly from the ASP.NET Report Viewer using the Print Control the print preview shows the report correctly in landscape orientation and page size, but the resulting printout is in portrait orientation and skewed or cropped.  If I go into the properti

Im trying to print the content of a listbox1 but the printing is false so all the pages coming out f

 ManagementObjectSearcher mosPrinter = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");                 foreach (ManagementObject moDiskete in mosPrinter.Get())                 {                     foreach (PropertyData p in moDiskete.Properties)                     {                           // listBox1.Items.Add(p.Value);                         listBox1.Items.Add(String.Format("{0}: {1}", p.Name, p.Value == null ? "NULL" :myprint.DocumentName=p.Value.ToString()));                      //   myprint.DocumentName = p.Value.ToString();                     

How to print pdf using shellExecute and close the adobe reader which is opened while printing?



I'm trying to print pdf file using shellExecute. Here is my code.

#region " CONSTANTS "
    private const int SW_SHOWNORMAL=2;
      #region " API "
      public static extern IntPtr ShellExecute(IntPtr hWnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
      #region " PUBLIC MEMBERS "
      public bool PrintPDF(string FilePath)
        if (System.IO.File.Exists(FilePath))
          if (ShellExecute((IntPtr)(1), "Print", FilePath, "", Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32() <= 32)
            return false;

            return true;
          return false;

      private void button1_Click(object sender, RoutedEventArgs e)

I get the selected pdf file printed. But, it leaves blank Adobe Reader window open. I want to close the adobe reader window from the program itself. Is there any way not to open the adobe reader window?

If somebody has any idea about this,

Printing Windows Application



In my Windows Application , there is a AxSHDocVw.AxWebBrowser which has some PDF page opened in it. its a ADOBE PDF. On click of Print button , print freezes and the whole application freezed. Please provide the solution for this.

Please let me know if the question is not clear.


Application Architecture in Windows Forms 2.0

Applications have special support in Windows Forms. For starters, you can manage and tailor your application's lifetime, and, when the work flow is disrupted by an unhandled exception, you can choose from several methods of response. Then, there are several application models that you can employ, including Single Document Interface (SDI) and Multiple Document Interface (MDI) applications, each of which can support either multiple-instance or single-instance mode, the former the VS05 default and the latter requiring special consideration. All applications, however, can discover and use a wide variety of information about the system and environment they execute in.

Application Architecture in Windows Forms 2.0-Single-MDI Applications

Consider an MDI application like Microsoft Excel; files opened from the file system (by double-clicking) are all opened as separate child windows within the parent Excel window.7 For the first instance of an MDI application to open a new child window to display the file that was passed to the second instance of the application, the second instance must be able to communicate with the initial instance.

How to programmatically add controls to Windows forms at run time by using Visual C#

Create a Windows Forms Application
Start Visual Studio .NET or Visual Studio 2005 or a later version, and create a new Visual C# Windows Application project named WinControls. Form1 is added to the project by default.
Double-click Form1 to create and view the Form1_Load event procedure.
Add private instance variables to the Form1 class to work with common Windows controls. The Form1 class starts as follows:

How to Localize Windows Forms and Change the Language at Runtime

Localization is the process of customizing your application to a particular language, culture or locale. Visual Studio provides support for localizing Windows Forms with much ease. In this article, we will see how to localize windows forms and give the user the ability to change to his preferred language at runtime.
When you run a localized application, the appearance is determined by two culture values. The UICulture property is used to specify which resource files will be loaded for the form. The Culture property, on the other hand, determines how strings such as dates, numerals, and currency amounts are formatted.
Let us see the steps required to create a localized form. You can then expand this example and adopt the same approach for the rest of the forms in your project

Localizing Windows Forms

The Visual Studio project system provides considerable support for localizing Windows Forms applications. There are two ways to generate resource files using the Visual Studio development environment: one is to have the project system generate the resource files for localizable UI elements such as text and images on the form. The resource files are then built into satellite assemblies. The second way is to add a resource file template and then edit the template with the XML Designer. A reason for doing the latter is to make localizable strings that appear in dialog boxes and error messages. You must then write code to access these resources.

This walkthrough topic demonstrates both processes in a single Windows Application project.

You can also convert a text file to a resource file; for more information, see Resources in Text File Format and Resource File Generator (Resgen.exe).


ASP.net Ajax TabContainer -- Printing All tabs



Can  anyone help me with this?. I want to print all the tabs in ajax tab container. The tab container has around 10 tabs. I dont want to goto each tab and print the page. Instead is there any way by which I can tweek the print.css file to print all the tabs at a single stretch?.  So that I will get all the contents of the tab in single print.  Is there any other way in which I can print all the tabs all together?.

Thanks in Advance...


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend