C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

How to get your default printer name?


Posted Date: 22 Feb 2004    Resource Type: Articles    Category: .NET Framework
Author: Shashijeevan M.P.Member Level: Silver    
Rating: 1 out of 5Points: 7



The PrintDocument object contains all the default settings for Printing.

The printing classes are in System.Drawing.Printing namespace.

The following code instantiates the PrintDocument object and displays the default Printer name.


PrintDocument pd = new PrintDocument();
MessageBox.Show(pd.PrinterSettings.PrinterName);


To get default printer without creating PrintDocument you have to use PInvoke services.

The following code displays the default printer using interop


[DllImport("winspool.Drv", EntryPoint="GetDefaultPrinter")]
public static extern bool GetDefaultPrinter(
StringBuilder pszBuffer, // printer name buffer
ref int pcchBuffer // size of name buffer
);

private void button3_Click(object sender, System.EventArgs e)
{
StringBuilder name = new StringBuilder();
int length=100;
GetDefaultPrinter(name, ref length);
MessageBox.Show(name.ToString());
}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Accessing the registry from C# code
Previous Resource: How to set your printing paper size through program?
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use