To get the default printer use the class PrinterSettings
(in English). Example:
var configImpressora = new PrinterSettings();
Console.WriteLine(configImpressora.PrinterName);
Note that this way you are using the Windows manager to get this information. And what you need to do to send the data is just the opposite.
Picking which is the default printer will not help much because it does not guarantee that the printer that is there is suitable for what you want. And even if you send it to her, it will send it to the Windows manager which is just what you DON’T want to do.
Unless I don’t know something about it, I doubt that part will help you at all.
The second part of the question:
Essentially you need to write directly on the door, normally PRN
or LPT1
or COM1
. sending directly to the port you avoid going through the Windows print manager,
Simplified example (does not have the quality that a code in production should have):
var impressora = new System.IO.StreamWriter(@"\\.\PRN");
impressora.Write((char)15); //inicia negrito na maioria das impressoras matriciais
impressora.Write("Teste");
impressora.Flush();
impressora.Close();
When I had to send it to a standard printer, that’s basically what I did.
If you need to choose where the printer is on each machine, I’m afraid you’ll have to have a local setting indicating where the printer is. It may be a simple text file, but it may be a local database, the Windows registry or simply allow the user to choose at the time of having it printed, which may be sufficient in many cases.
I put in the Github for future reference.