printing - How to print rectangle with exact size in c#? -


i new dot net, want print rectangle 20mm width , 8mm height if measure scale. want print text in middle of rectangle.can suggest me how can achieve this?


i sorry not being clear earlier. have tried using "pageunits" working fine. however, have problem margins.

i able print correct margins(8.8mm left , 22mm top) if using printer "hp laserjet p2035n". if print using "canon ir2020 pcl5e" getting incorrect margins(8.1mm left , 8.0mm top) should 8.8mm left , 22mm top margins. can explain me doing wrong.

using system; using system.collections.generic; using system.linq; using system.text; using system.drawing; using system.drawing.printing; namespace consoleapplication6 {     class drawshape     {         public static void drawrec()         {             printdocument doc = new printdocument();             doc.printpage += doc_printpage;             doc.print();         }          static void doc_printpage(object sender, printpageeventargs e)         {             graphics g = e.graphics;             pagesettings pageset = new pagesettings();             float marginx = pageset.printablearea.x;             float marginy = pageset.printablearea.y;             float x = (float)(8.8-((marginx/100)*25.4));             float y = (float)(22-((marginy/100)*25.4));             g.pageunit = graphicsunit.millimeter;             g.drawrectangle(pens.black, x, y, 20, 8);          }     } } 

you may want start this:

    private void button1_click(object sender, eventargs e)     {         using (graphics formgraphics = this.creategraphics())         {             formgraphics.pageunit = graphicsunit.millimeter;             formgraphics.drawrectangle(pens.blue, 0, 0, 20, 80);         }     } 

you can using drawstring on graphics object draw text inside rectangle.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -