Solved

Default Printer

Posted on 2004-10-13
2
197 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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