Solved

Default Printer

Posted on 2004-10-13
2
195 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
Comment Utility
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
Comment Utility
You are correct.  I needed to not set it.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

10 Experts available now in Live!

Get 1:1 Help Now