How to get info from a PrintDialog box

Posted on 2006-06-06
Last Modified: 2012-06-21
I'm trying to get a couple of things from a PrintDialog box:  I need to know if the "All", "Pages", or "Selection" radio button has been pushed and, if the "Pages" radiobutton is pushed, what pages have been entered.

I use the following code to determine whether the OK button is pushed, but I can't find much help on the AllowPrintPages and AllowSelection properties.

                PrintDocument* pdoc = new PrintDocument();
      PrintDialog* pd = new PrintDialog();

      pd->Document = pdoc;

      if (pd->ShowDialog() == DialogResult::OK)
Question by:restabro
    LVL 48

    Expert Comment

    PrintDialog.PrinterSettings property returns PrinterSettings which contains this information.

    Author Comment

    That gets me a little closer, but please provide coding examples for the following conditions:

    1.  Determining if the "All" button has been selected

    2.  Determining if the "Pages" button has been selected

    3.  If the "Pages" button has been selected, how to determine what the "From" page is

    4.  Determining if the "Selection" button was pushed

    Note that I increased the point total to 500. Thank you.

    LVL 49

    Accepted Solution

    These things are all clearly documented, including example code:

    The "Pages" radio button was clicked if
       PrintDialog.UserPageRangeEnabled is true
       and PrintDialog.PrinterSettings.PageRangeSelection is PageRangeSelection.UserPages

    The "Selection" radio button was clicked if
          PrintDialog.PrinterSettings.PageRangeSelection is not none

    The "All" radio button was clicked if
          PrintDialog.PageRangeSelection is AllPages

    The "Selection" radio button was clicked if
          PrintDialog.PageRangeSelection is not PageRangeSelection.None

    The "From" is valid when
       PrintDialog.PageRangeSelection is PageRangeSelection.UserPages

       It can ve found by examining the first PageFom member of the first PageRange
       item in PrintDialog.PageRanges

    -- Dan

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now