Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. position of the printed out datagrid

position of the printed out datagrid

Scheduled Pinned Locked Moved C#
graphicshelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MJay
    wrote on last edited by
    #1

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(0,0,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); } this is the coding i used to print out datagrid, the X and Y is set to 0 and 0, the datagrid print out correctly at exactly upper left corner of the paper. then i modify the coding. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(50,50,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); } i change the cordinates to 50,50, but y the datagrid still print at the same position for cordinates 0,0??i do not wan the datagrid to be printed at that position!anyone can help me out with this??Thz!

    A 1 Reply Last reply
    0
    • M MJay

      private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(0,0,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); } this is the coding i used to print out datagrid, the X and Y is set to 0 and 0, the datagrid print out correctly at exactly upper left corner of the paper. then i modify the coding. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(50,50,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); } i change the cordinates to 50,50, but y the datagrid still print at the same position for cordinates 0,0??i do not wan the datagrid to be printed at that position!anyone can help me out with this??Thz!

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      You could create a bitmap with the needed dimension, create a Graphics object for it, paint the grid to this bitmap and finally draw the bitmap onto the page:

      Bitmap b = new Bitmap(datagrid1.Width,datagrid1.Height);
      using (Graphics bg = GraphicsFromImage(b)) {
      PaintEventArgs myPaintArgs = new PaintEventArgs (bg , new Rectangle(0,0,datagrid1.Width,datagrid1.Height));
      this.InvokePaint(dg, myPaintArgs);
      }
      e.Graphics.DrawImageUnscaled(b, 50, 50);

      M 1 Reply Last reply
      0
      • A Anonymous

        You could create a bitmap with the needed dimension, create a Graphics object for it, paint the grid to this bitmap and finally draw the bitmap onto the page:

        Bitmap b = new Bitmap(datagrid1.Width,datagrid1.Height);
        using (Graphics bg = GraphicsFromImage(b)) {
        PaintEventArgs myPaintArgs = new PaintEventArgs (bg , new Rectangle(0,0,datagrid1.Width,datagrid1.Height));
        this.InvokePaint(dg, myPaintArgs);
        }
        e.Graphics.DrawImageUnscaled(b, 50, 50);

        M Offline
        M Offline
        MJay
        wrote on last edited by
        #3

        thz man!the coding works for me.. but there is another problem, my datagrid has been loaded with a datatable contains 31 records, under screen resolution of 1024*768, the screen is able to show and print out all the records, but if user change screen resolution to 800*600, the records that can show in one screen is only 21 records, the rest of the records needed to be scroll down to view, then the datagrid printed out only contains 21 records that can be shown on the screen... wat should i do??:doh:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups