Solved

Default Printer

Posted on 2004-10-13
2
196 Views
Last Modified: 2010-04-15
How do I print to the default printer..............based upon this code.........what would I change i the code?



private void buttonPrintSearchResults_Click(object sender, System.EventArgs e)
            {
                  try
                  {
                        string use_printer="";

                        DataSet ds = this.GenerateInternalDataSet(this.textBoxSearchString.Text);                        
                        OnExportGridToCSV(ds);

                        this.richTextBoxSearchExport.LoadFile(@"C:\search_export.txt", RichTextBoxStreamType.PlainText);

                        foreach(string p_rinter in PrinterSettings.InstalledPrinters)
                        {
                              use_printer = p_rinter;
                        }

                        PrintDocument pd = new PrintDocument();
                        pd.PrinterSettings.PrinterName = use_printer;
                        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                        pd.Print();
                  }
                  catch(Exception ee)
                  {
                        System.Diagnostics.Debug.WriteLine(ee);
                  }

            }

            private void pd_PrintPage(object sender, PrintPageEventArgs ev)
            {
                  Graphics g = ev.Graphics;
                  Font font = new Font("Arial", 16);
                  SolidBrush brush = new SolidBrush(Color.Black);

                  g.DrawString(this.richTextBoxSearchExport.Text,font, brush, new Rectangle(20,20,200,100));
            }
0
Comment
Question by:knowlton
2 Comments
 
LVL 3

Accepted Solution

by:
a_goat earned 500 total points
ID: 12301268
Just don't set the PrinterName.  It'll automatically print to the default printer using the default printer settings.
0
 
LVL 5

Author Comment

by:knowlton
ID: 12302659
You are correct.  I needed to not set it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

911 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

19 Experts available now in Live!

Get 1:1 Help Now