Click here to Skip to main content
15,504,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to get the pagesize unit of a printer (that can be set from the printer setup dialog>layout tab via a combobox) in a label. I want to user to know that it is in Inch, centimetre or millimeter.
thank you in advance for your help.

What I have tried:

I can get pinter name, page kind, paper size and other parameters, but I cannot get the printerunit. there is an Enum but i have no idea that how can use from it.
Posted
Updated 7-Jul-19 5:09am

The printer units are used by the program that creates the printer output to format the text/images, based on the orientation and size of the selected print device and paper. The printer itself has no concept of these values.
 
Share this answer
 
Comments
Member 13325846 6-Jul-19 10:47am    
Hi,
Thanks for your answer.
I have a software that gets the unit of set paper size in the layout tab of the printer setup dialog box in a lable(e.g. width:21.7cm). that is why i say this is possible, but i had surfed many sites and I have found no related topic.
Richard MacCutchan 6-Jul-19 13:35pm    
Yes, that is the paper size, in the default units of the system locale. What else are you looking for?
Member 13325846 6-Jul-19 13:54pm    
How can I get its dimention? means inch, cm or mm?
Richard MacCutchan 6-Jul-19 15:47pm    
You have the dimension: 21.7 cm. What exactly are you trying to get?
Member 13325846 6-Jul-19 16:28pm    
I cannot to have unit (cm) i want to have the unit in a lable. 21.7 without its unit is accessible in paper size properties. do you any way to have the selected unit from printer setup dialog box?
I changed the Unit Of Metrics to Centimeter, Millimeter and inch but it only gives the pagesize width & Height in One-hundred of inches, So:

C#
In FormA_Load 
{
            PageSettings pgSting = new PageSettings();
           
            lblPaperSizeReslt.Text = "Width: " + ((Math.Round((double)pgSting.PaperSize.Width, 2)) / 100).ToString() + "In" +
                " × " + "Height: " + ((Math.Round((double)pgSting.PaperSize.Height, 2)) / 100).ToString() + "In";
}


And also on a button click:


C#
private void xBtnPrntrSetup_Click(object sender, EventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            pd.ShowDialog();

            lblPaperSizeReslt.Text = "Width: " + ((Math.Round((double)pd.PrinterSettings.DefaultPageSettings.PaperSize.Width,2))/100).ToString() +"In"+
                " × " + "Height: " + ((Math.Round((double)pd.PrinterSettings.DefaultPageSettings.PaperSize.Height,2))/100).ToString()+ "In";

        }


This may be simple for somebody but also may save some others time. I hope this help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900