I have a small child form (dialog) in my c# application that loads the available printers on the machine/network into a listbox in the Load event, and in the Shown event selects the one in the list that is the Default printer
Trouble is, even though there are only about 8 available printers there is still a noticable load time of a second or two, so I'm thinking that mycode is wrong.
here is my code (taken from another post on StackOverFlow about getting/setting the default printer):
using System;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections.Generic;
private void frmPrinters_Shown(object sender, EventArgs e)
{
PrinterSettings settings = new PrinterSettings();
foreach (string printer in PrinterSettings.InstalledPrinters)
{
settings.PrinterName = printer;
if (settings.IsDefaultPrinter)
{
this.lstAvailablePrinters.SelectedItem = printer;
}
}
}
private void frmPrinters_Load(object sender, EventArgs e)
{
List<string> lstOfPrinters = new List<string>();
foreach (var item in PrinterSettings.InstalledPrinters)
{
this.lstAvailablePrinters.Items.Add(item.ToString());
}
//listAllPrinters();
}
public static class myPrinters
{
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDefaultPrinter(string Name);
}
is there some different way to handle this, or better way, or what am I doing wrong?
thanks Philip