Solved

Default Printer

Posted on 2004-10-13
2
200 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Tom Knowlton
ID: 12302659
You are correct.  I needed to not set it.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to Office 1 68
Inserting LocalDB Table to SQL Server C# 3 51
Put File 6 38
How does this modal work? 3 34
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

710 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