Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 26th, 2006, 08:11 AM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# Printing

Can anyone help me out with this printing problem? I am trying to print a document and have written the following:

public class PrintMe()
{
    private PrintDocument printDoc = new PrintDocument();
    public PrintMe()
    {
        printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);

        printDoc.Print();
    }

    private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)
        {
            String textToPrint = "The Doc Header";
            Font printFont = new Font("Courier New", 12, FontStyle.Bold);
            e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, 0, 0);
        }
}


I added this code to a small Windows application just for testing purposes and it worked. Having tested it I wanted to add it to a web application I am working on and did the following:
I added PrintMe class to the code behind file which happened to be called top.aspx.cs (outside 'top' class of course), then I added a HtmlAnchor called lnkPrint to the page and added an event handler:
private void lnkPrint_ServerClick(object sender, EventArgs e)
{
 PrintMe pm = new PrintMe();
}.

The handler works and makes a call to PrintMe and everything is OK up to the point when printDoc.Print() is called and trying to execute it the application freezes forever. The target printer is connected (I checked) and works.
Is this method of printing meant to work in Web apps at all or I am missing some silly little thing?

Janette.

 
Old May 28th, 2006, 10:33 AM
Authorized User
 
Join Date: Mar 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dont know much abt printing from web forms. Yet, the issue could be something to with security, may be?

Sreeram
 
Old January 17th, 2007, 01:25 PM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Janette

I am having the same problem with printing the webforms

did you ever get a solution to this problem?








Similar Threads
Thread Thread Starter Forum Replies Last Post
Help about printing Fahim Crystal Reports 0 November 12th, 2006 11:14 PM
Printing Arunachalam Beginning VB 6 2 October 12th, 2006 07:44 AM
Printing uchkid Pro Visual Basic 2005 1 September 7th, 2006 03:37 AM
capturing printing settings when printing reports nikolaosk Access VBA 0 February 8th, 2005 04:14 AM
Printing NiNe ADO.NET 5 April 7th, 2004 04:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.