Custom units of measurement RRS feed

  • Question

  • User-80781307 posted


    I have a question about custom units of measurement.  I want to use GDI+ because I will have to draw vector objects and plain old GDI won't cut it.  I am writing software for hardware which basically uses measurements that aren't typical (the measurements are 5000/12 == 1 inch).  So, is there a way to use SetPageUnit() to use my custom measurement?  If not, how would I accomplish this?  This code works for me, but it's GDI, not GDI+:

    	static const float INCH = 5000.0f/12.0f;
    	CRect rc;
    	dc.SetViewportOrg(0, 0);
    	dc.SetWindowExt(INCH*12, INCH*12);
    	dc.SetViewportExt(rc.Width(), rc.Height());
    	dc.TextOut(INCH*2,INCH*5,"Hello World");

    This would draw "Hello World" at 2",5" perfectly.  I noticed that if i run this code, then attach a Graphics object to the CDC it keeps the units, but i don't know if that is the proper way to do this in GDI+, which is why i am here!

    Thanks for any tips!


    Monday, October 19, 2009 10:28 PM


  • User-80781307 posted

    OK, i think i figured it out...

    What i can do is use SetPageUnit(UnitDocument), then just make the size of the area 5000x5000 (drawing a rectangle 5000x5000 which is 12"x12" on the target hardware), then just use SetTransform to "zoom" out.  This way i get an area that is 5000x5000 "static" units (i.e. the area looks the same on any computer)

    If i am way off, just let me know... but in the meantime i will try to work with this...



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 20, 2009 12:51 AM