Home > OS >  How to get "Selection" radio button value from C# PrintDialog Class
How to get "Selection" radio button value from C# PrintDialog Class

Time:05-04

I have a very simple use case in C#. I want to print a document (image) in C# using the PrintDialog class. By default, I print the entire image, but if the user ticks the "Selection" radio button, I want to print only the portion of the image (selected by the user previously).

I have almost everything covered, but I could find any MSDN documentation or sample, on how to get those radio button states once the user hit Print on the dialog.

PrintDialog pdlg = new PrintDialog();
pdlg.AllowSelection = true;
pdlg.Document = pd;

if (pdlg.ShowDialog() == DialogResult.OK)
{
    // how to get the Selection radiobutton state?
    pd.Print();
}

For me, it seems a pretty obvious request to be able to get the state of the radio button. MSDN documentation and sample codes only cover how to Enable this radio button, before you show it to the user, but never mention how to get the state of it, as you would like to use it for something.

PrintDialog

Does anyone know how to get the state of those radio buttons? Thank you for the help!

CodePudding user response:

You can check the value of PrinterSettings.PrintRange property. For example:

printDialog1.AllowSelection = true;
if(printDialog1.ShowDialog() == DialogResult.OK)
{
    if (printDialog1.PrinterSettings.PrintRange == 
        System.Drawing.Printing.PrintRange.Selection)
        MessageBox.Show("Selection");
}
  • Related