There are 3 printers in the printer list, but is there a way to hide or disable one of them when I call the printdialog? For example, how to disable or hide the printers which names start with "Brother MFC", so that only allows users to select "HP" printers?
PrintDialog printDlg = newPrintDialog();
PrintDocument printDoc = newPrintDocument();
printDoc.DocumentName = "Print Document";
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
//Call ShowDialog
if (printDlg.ShowDialog() == DialogResult.OK) printDoc.Print();
Related
I wrote(copied) a small code to select some image files and print it every five minutes.
When it prints, the image doesn't fit to the paper. It's smaller or bigger. So I want to fit the Images to an A4 Page Size.
I couldn't find any properties for that.
Is there a way to do that?
Here is my code:
private async void button1_Click(object btnSender, EventArgs e)
{
// Set the file dialog to filter for graphics files.
this.openFileDialog1.Filter =
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
"All files (*.*)|*.*";
// Allow the user to select multiple images.
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "My Image Browser";
DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
// Read the files
foreach (string file in openFileDialog1.FileNames)
{
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = "Print Document";
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
printDoc.DefaultPageSettings.Landscape = true;
printDoc.PrintPage += (sender, args) =>
{
Image i = Image.FromFile(file);
Point p = new Point(0, 0);
args.Graphics.DrawImage(i, p);
};
printDoc.Print();
await Task.Delay(300000);
}
Process.Start("shutdown.exe", "-s -t 00");
}
}
You do not need to define Point;
To fit image to a page just use args.Graphics.DrawImage(i, args.PageBounds);
instead of args.Graphics.DrawImage(i, p);
in C# Winform, i'm sending an Image to the printer using the PrintDialog... using this code:
private void PrintSnippedImage()
{
PrintDocument pDoc = new PrintDocument();
pDoc.PrintPage += PrintPage;
PrintDialog pDialog = new PrintDialog();
pDialog.ShowHelp = true;
pDialog.AllowSelection = false;
pDialog.AllowSomePages = false;
pDialog.Document = pDoc;
if (pDialog.ShowDialog() == DialogResult.OK)
{
pDoc.Print();
};
}
private void PrintPage(object o, PrintPageEventArgs e)
{
System.Drawing.Image img = Glob.SnippedImage;
Point loc = new Point(10, 10);
e.Graphics.DrawImage(img, loc);
}
I get a popup that shows "Printing... Page 1 of document" with a Cancel button.
it appears in seemingly random locations on one of my monitors.
is there a way to inhibit this popup, or at least force it to appear on the monitor in the general location of the application that called it?
it looks like this:
It should be a case of swapping the PrintController implementation from PrintControllerWithStatusDialog (the default) to StandardPrintController. See https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument.printcontroller?view=dotnet-plat-ext-6.0#system-drawing-printing-printdocument-printcontroller
i am working on a c# console application but want to know :
if it is possible to show the PrintDialog in a console application ?
If you want to print something from your console application and want PrintDialog, you can use the below code.
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = "Print Document";
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
//Call ShowDialog
if (printDlg.ShowDialog() == DialogResult.OK) printDoc.Print();
I have such a problem here. I have a window in my WPF project, and have a button, with what I want To print With printer that page. My click event for that button is this.
PrintDialog dlg = new PrintDialog();
Window currentMainWindow = Application.Current.MainWindow;
Application.Current.MainWindow = this;
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
Application.Current.MainWindow = currentMainWindow;
}
When I click on buton, the Print dialog is popped out.
Here
But When clicking on print, nothing happenes, the dialog is just closing, and no results, it is not working not with Adobe PDF, not with ARX CoSign...
What to do ? Thanks
The rough working
var printDoc = new PrintDocument()
var dlg = new PrintDialog()
If(dlg.ShowDialog() == DialogResult.OK)
{
printDoc.Document = [doc to print]
printDoc.Setting = dlg.settings
PrintDoc.print()
}
enter code here
PrintDialog dlg = new PrintDialog();
Window currentMainWindow = Application.Current.MainWindow;
Application.Current.MainWindow = this;
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
Application.Current.MainWindow = currentMainWindow; // do it early enough if the 'if' is entered
dlg.PrintVisual(this, "Certificate");
}
Here is the code I use (just the printing-related part):
Button 1 onclick handler method:
printDialog1 = new PrintDialog();
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = false;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 826, 1169);
pd.PrinterSettings.PrintToFile = true;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
And my pd_PrintPage method:
Bitmap bitmapCanvas = new Bitmap(1000, 1000);
Graphics g = Graphics.FromImage(bitmapCanvas);
g.Clear(Color.White);
...
some g.Draw...() stuff
...
e.Graphics.DrawImage(bitmapCanvas, A(2), A(2));
//where e is the PrintPageEventArgs defined in the method signature
First part of my problem is that, this doesn't print to the selected printer (selected on the print dialog).
It only prints to a printer if that is the default printer.
Under Windows 7 it works, it recognizes the default printer, so the default printer will be selected by default in the comboBox on the print dialog which comes up after I click the button.
My main problem is that, this doesn't work under Windows Xp at all (unfortunately I only can use that). And I'm kind of curious why. So I don't know if I made a mess, or it is not supported under Windows Xp.
With what should I complete or correct my code?
Any help is appreciated and thank you very much!
Mitulat bati
Try this,
printDialog1 = new PrintDialog();
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = false;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
printDialog1.Document.DefaultPageSettings.PaperSize = new PaperSize("A4", 826, 1169);
printDialog1.Document.PrinterSettings.PrintToFile = true;
printDialog1.Document.PrintPage += new PrintPageEventHandler(pd_PrintPage);
printDialog1.Document.Print();
}