GeneralTopics include: .NET Framework Note: Most posts can be categorized into one of the forums below, where experts on that topic will be able to help you find a solution to your problem faster and more efficiently.
Hi everybody!
-
Does anyone have any idea how could I set the default printer from my C# code ?
--
I would like to reach the same result as I would set the default printer from Control Panel/Printer !
--
What classes should I use?
--
Thanks in advance for replies
Thank you for your early reply ! Thank you ver ymuch
But I still need your help !
--
you use : using mshtml !!!!!! my question is what dll do I have to import(add references) . In which dll do I find this namespace ?
--
You wrote
internal RegistryPrinter(string name, string value)
{
this.name = name;
this.value = value;
}
I can give my printer's name but it's quite difficult to get the printer's registry(value). Could you show me how did you manage to call this RegistryPrinter class !
--
Tnaks in advance
you can take out the line that says include mshtml
I don't know how it got there (probably copy/paste) but it's not needed for that class. It's from the ms html object library, a com object. I use it for html parsing.
RegistryPrinter.InstalledPrinters returns an array of RegistryPrinter objects. Each RegistryPrinter object in the array represents a printer that's available in the user's controlPanel->Printer. When u find the printer u want to set as the default, invoke RegistryPrinter.SetAsDefaultPrinter. Each RegistryPrinter also has a Name and Value property. The Value property is the registry value and the Name property is the name of the printer, as it is displayed in ControlPanel->Printers.
Ohh my God I'm so stupid, I could have noticed that before (to use RegistryPrinter.InstalledPrinters).
--
Imagine that I used PrinterSettings.InstalledPrinters where I got only the name and when I instantiated an object from RegistryPrinters class I didn't know what parameters to give.That's why I had difficulty in how to call from outside, to get a registry value !
--
Your code is marvelous and now it works !!!!!!!!!!!!!!
You almost saved my "life" because I had been working on it for 2 days and till you gave the answer I didn't manage with it !
-
Thank you very much !
Bye
Pop Marius from Hungary
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET. subscribe