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. Printing Graphics

Printing Graphics

Scheduled Pinned Locked Moved C#
graphicsquestion
5 Posts 4 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.
  • R Offline
    R Offline
    rognog
    wrote on last edited by
    #1

    Hello all, I am working on a program that displays descision trees in a panel control. The links between the nodes are drawn straight on to the panel whereas the nodes are custom controls. Trying to print the contents of the panel I have used GetImage, unfortunately this only gives me the links and not the nodes. I suspect having studied further I should have drawn the whole lot to a graphics path... any way I can bodge it without rewriting all the graphics code? I wish to keep the custom controls as they allow me to process mouse events easily. Rob

    B D H 3 Replies Last reply
    0
    • R rognog

      Hello all, I am working on a program that displays descision trees in a panel control. The links between the nodes are drawn straight on to the panel whereas the nodes are custom controls. Trying to print the contents of the panel I have used GetImage, unfortunately this only gives me the links and not the nodes. I suspect having studied further I should have drawn the whole lot to a graphics path... any way I can bodge it without rewriting all the graphics code? I wish to keep the custom controls as they allow me to process mouse events easily. Rob

      B Offline
      B Offline
      benjymous
      wrote on last edited by
      #2

      What you could do is create an Image object (as a member of your form class), give that to the PictureBox's Image property, then do all your drawing operations onto the Image itself instead of the picturebox (you can get a Graphics handle just as easily from the Image, so your code should need only minor modifications) -- Help me! I'm turning into a grapefruit! Phoenix Paint - back from DPaint's ashes!

      H 1 Reply Last reply
      0
      • R rognog

        Hello all, I am working on a program that displays descision trees in a panel control. The links between the nodes are drawn straight on to the panel whereas the nodes are custom controls. Trying to print the contents of the panel I have used GetImage, unfortunately this only gives me the links and not the nodes. I suspect having studied further I should have drawn the whole lot to a graphics path... any way I can bodge it without rewriting all the graphics code? I wish to keep the custom controls as they allow me to process mouse events easily. Rob

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        You can write any window to a DC using Windows API as it's being shown on the screen. You first need to call CreateDC("DISPLAY", null, null, null) and then use SendMessage to send a WM_PRINT to the window. Alternatively, you'll need to rewrite your code and draw everything on the Panel's OnPaint. Yes, even I am blogging now!

        1 Reply Last reply
        0
        • B benjymous

          What you could do is create an Image object (as a member of your form class), give that to the PictureBox's Image property, then do all your drawing operations onto the Image itself instead of the picturebox (you can get a Graphics handle just as easily from the Image, so your code should need only minor modifications) -- Help me! I'm turning into a grapefruit! Phoenix Paint - back from DPaint's ashes!

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          That would be a complete waste of memory and CPU cycles. The OnPaint virtual function and the event if fires - Paint - exist so that you can draw onto any control. Drawing into an images then assigning that images to a PictureBox is inefficient and requires much more memory than drawing on the control's surface itself. That can be done with a simple Panel as the poster is currently doing. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

          1 Reply Last reply
          0
          • R rognog

            Hello all, I am working on a program that displays descision trees in a panel control. The links between the nodes are drawn straight on to the panel whereas the nodes are custom controls. Trying to print the contents of the panel I have used GetImage, unfortunately this only gives me the links and not the nodes. I suspect having studied further I should have drawn the whole lot to a graphics path... any way I can bodge it without rewriting all the graphics code? I wish to keep the custom controls as they allow me to process mouse events easily. Rob

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            Extending on what Daniel said, you should rewrite your OnPaint to paint the entire surface (nodes and lines) but in a modular manner that you can pass a Graphics object (and perhaps the clip bounds) to paint on, but don't paint directly in OnPaint. This allows you to pass the Graphics for a PrintDocument (or even an HDC for some other device using Graphics.FromHdc) and use the same drawing routines. The common solution follows:

            private void Paint(Graphics g, Rectangle bounds)
            {
            // Your drawing routines go here...
            }
             
            protected override void OnPaint(PaintEventArgs e)
            {
            base.OnPaint(e);
            Paint(e.Graphics, Bounds);
            }
             
            private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
            {
            Paint(e.Graphics, e.PageBounds);
            }

            Handling your mouse events isn't too hard if you design a nice abstract system of nodes where the Panel may translate mouse events to the nodes, but the nodes actually contain the code to move themselves. Polymorphism is a very powerful tool. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

            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