TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tamil Rk
1.3k
451
17.5k
How to print the files without affecting the default printer setting?
Jul 27 2020 3:14 AM
I have checked with the "Let \Windows manage my default Printer" checkbox in Printer & Scanners setting, if I used the below code for printing my document, it is changing the default printer from Printer & Scanners setting.
public
void
Print(
string
FileName,
int
pintprintqty)
{
if
(
string
.IsNullOrWhiteSpace(FileName))
return
;
// Prevents execution of below statements if filename is not selected.
PrintDocument pd =
new
PrintDocument();
//Disable the printing document pop-up dialog shown during printing.
PrintController printController =
new
StandardPrintController();
pd.PrintController = printController;
pd.PrinterSettings.PrinterName = cmbLabelPrinter.Text.ToString();
pd.PrinterSettings.Copies = Convert.ToInt16(pintprintqty);
pd.DefaultPageSettings.Landscape =
false
;
pd.DefaultPageSettings.Margins =
new
Margins(0, 0, 0, 0);
pd.PrinterSettings.DefaultPageSettings.Margins =
new
Margins(0, 0, 0, 0);
pd.PrintPage += (sndr, args) =>
{
System.Drawing.Image i = System.Drawing.Image.FromFile(FileName);
//Adjust the size of the image to the page to print the full image without loosing any part of the image.
System.Drawing.Rectangle m = args.MarginBounds;
//Logic below maintains Aspect Ratio.
if
((
double
)i.Width / (
double
)i.Height > (
double
)m.Width / (
double
)m.Height)
// image is wider
{
m.Height = (
int
)((
double
)i.Height / (
double
)i.Width * (
double
)m.Width);
}
else
{
m.Width = (
int
)((
double
)i.Width / (
double
)i.Height * (
double
)m.Height);
}
//Calculating optimal orientation.
pd.DefaultPageSettings.Landscape = m.Width > m.Height;
pd.DefaultPageSettings.Landscape =
false
;
//New
args.Graphics.DrawImage(i, m);
};
pd.Print();
}
How to print the document without changing the default printer setting in "Let Windows manage my default Printer" checkbox checked mode?
Reply
Answers (
0
)
I want to decrease textbox value by 0,15 every second with timer tick.
Function in User control