:: Home

  login:         
  passwords:  

Winforms Interview Questions

Windows Forms Deployment
Windows Forms Controls
Windows Forms Data Binding
Windows Forms Datagrid
Windows Forms Docking
Windows Forms Keyboard Handling
Windows Forms Layout
Windows Forms Licensing
Windows Forms Menus
Windows Forms Mouse Handling
Windows Forms from MFC
Windows Forms from VB6
Windows Forms Patterns
Windows Forms Printing
Windows Forms Resources
Windows Form Scrolling
Windows Forms Tips
Windows Forms Common Dialogs
Windows Forms Listbox
Windows Forms ComboBox
Windows Forms Rich TextBox
Windows Forms ListView
Windows Forms TreeView
Windows Forms Button
Windows Forms TabControl
Windows Forms TextBox
Windows Forms MDI
Windows Forms Cursors
Windows Forms WebBrowser
Windows Forms PictureBox
Windows Forms Form
Windows Forms MDI
Windows Forms In IE
GDI+Bitmaps&Images
GDI+Font
GDI+Color
GDI+Brushes
GDI Drawing Tips
GDI+ from GDI
GDI Paths Regions
GDI+Pens
Interioerability WIn32
Tools Metadata Viewers
Design Time Serialization
Design Time Custom Designers
Design Time Tips
Design Time Type Editors
Vs.Net Tips
Vs.Net Debugging
Vs.Net Macros
Framework Tips General
Framework Tips Events
Framework Tips General IO
Framework Tips Strings
Framework Tips Threading
Tool Resource Editor
Design Time UI
Framework Tips CGI
Framework Tips XML

WPF Interview Qs

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Windows Forms Printing

The General Winforms Interview Questions consists the most frequently asked questions in Winforms. This list of 100+ questions guage your familiarity with the Winforms platform. The q&a have been collected over a period of time from various blogs, forums and other similar Winforms sites

14. Windows Forms Printing

    14.1 How do I print a form?
    14.2 How do I display the PrintPreview maximized and control its zooming?

14.1 How do I print a form?

I am afraid there is not a very easy way to print a form. You may implement this function with the steps below:

1. Add a print function to your application.
To do this, you should add a PrintDocument component to your application.
Please drag a PrintDocument from the tool box to your form. After that, you
should create a PrintDialog and add the code to print the document.
private void buttonPrint_Click(object sender, System.EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = printDocument1;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{


printDocument1.Print();
}
}
For detailed information about print framework, please see "Windows Forms
Print Support" in the MSDN (October 2001).
2. Draw the form when printing.
This step is a little complex. You should handle the PrintPage of the
printDocument1 and draw the form to the printer device. In the event you
may copy the form to an image and then draw it to the printer device.
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics graphic = this.CreateGraphics();
Size s = this.Size;
Image memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, 13369376);
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
e.Graphics.DrawImage(memImage,0,0);
}
The above referenced the article "Screen Capturing a Form in .NET - Using
GDI in GDI+" by Michael Gold. You may find it at:
http://www.c-sharpcorner.com/Graphics/ScreenCaptFormMG.asp
3. Declare the API function.
Please note the BitBlt function used in Step 2. It is an unmanaged
function. You should use DllImportAttribute attribute to import it to your
code. Although, this is the Step 3, you may perform this step any time.
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code


);
For more information about DllImportAttribute attribute please see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemRuntimeInteropServicesDllImportAttributeClassTopic.asp


14.2 How do I display the PrintPreview maximized and control its zooming?

You can use the WindowState property of the PrintPreviewDialog class to bring the PrintPreview maximized. To handle zooming, the PrintPreviewDialog has a property, PrintPreviewControl. PrintPreviewControl owns a Zoom property that allows you to set the zoom factor of the PrintPreview.

Copyright 2007, Megasolutions Ltd