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. BufferedGraphics object will AutoScroll position

BufferedGraphics object will AutoScroll position

Scheduled Pinned Locked Moved C#
questionhtmlgraphicshelptutorial
2 Posts 1 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.
  • C Offline
    C Offline
    Chris Copeland
    wrote on last edited by
    #1

    Hi guys, I've been working on a custom component which acts as a 'view' control, such that it manually paints cells for child items. The component can contain hundreds of child items, which means that I've had to utilise the BufferedGraphics object for maintaining the graphics, and reset it only when the component is resized or when the child items are changed. Each child items also owns it's own BufferedGraphics object to maintain the rendering of each item (since these items can contain an Image in the graphics, it speeds up the painting considerably.) A problem surfaces when I start to take into account scrolling through the use of AutoScroll and AutoScrollPosition. I've spent a good while trying to search for an answer to applying the scroll position offset to a BufferedGraphics and I've yet yielded unsuccessful results. Several problems are standing in the way of the scrolling functionality: 1. Graphics.TranslateTransform() or Graphics.Transform = new Matrix() does not translate a BufferedGraphics.Render() operation. I believe this is namely because the Render() function just paints directly onto the Graphics handle for the region it was allocated by. For example, the below does not work:

    override void OnPaint(PaintEventArgs e)
    {
    // code here which deals with allocating the buffer if it needs creating

    // translate by the auto scroll position
    e.Graphics.TranslateTransform(-AutoScrollPosition.X, -AutoScrollPosition.Y);
    
    // render the buffered graphics onto the graphics handle for the paint event
    this.bufferedGraphics.Render(e.Graphics);
    

    }

    2. Following the code in this example [^] results in many invalidations, which causes the graphics to lag to the point that it's infeasible for the component. My question is, is there a reliable method of being able to translate the buffered graphics of a BufferedGraphics object when painting onto a Graphics handle? For instance, could I allocate my BufferedGraphics as I do in point #1, and intrinsically invalidate the component upon scrolling and simply offset the buffered graphics depending on the position the user has scrolled to? If not, can anyone recommend a suitable repla

    C 1 Reply Last reply
    0
    • C Chris Copeland

      Hi guys, I've been working on a custom component which acts as a 'view' control, such that it manually paints cells for child items. The component can contain hundreds of child items, which means that I've had to utilise the BufferedGraphics object for maintaining the graphics, and reset it only when the component is resized or when the child items are changed. Each child items also owns it's own BufferedGraphics object to maintain the rendering of each item (since these items can contain an Image in the graphics, it speeds up the painting considerably.) A problem surfaces when I start to take into account scrolling through the use of AutoScroll and AutoScrollPosition. I've spent a good while trying to search for an answer to applying the scroll position offset to a BufferedGraphics and I've yet yielded unsuccessful results. Several problems are standing in the way of the scrolling functionality: 1. Graphics.TranslateTransform() or Graphics.Transform = new Matrix() does not translate a BufferedGraphics.Render() operation. I believe this is namely because the Render() function just paints directly onto the Graphics handle for the region it was allocated by. For example, the below does not work:

      override void OnPaint(PaintEventArgs e)
      {
      // code here which deals with allocating the buffer if it needs creating

      // translate by the auto scroll position
      e.Graphics.TranslateTransform(-AutoScrollPosition.X, -AutoScrollPosition.Y);
      
      // render the buffered graphics onto the graphics handle for the paint event
      this.bufferedGraphics.Render(e.Graphics);
      

      }

      2. Following the code in this example [^] results in many invalidations, which causes the graphics to lag to the point that it's infeasible for the component. My question is, is there a reliable method of being able to translate the buffered graphics of a BufferedGraphics object when painting onto a Graphics handle? For instance, could I allocate my BufferedGraphics as I do in point #1, and intrinsically invalidate the component upon scrolling and simply offset the buffered graphics depending on the position the user has scrolled to? If not, can anyone recommend a suitable repla

      C Offline
      C Offline
      Chris Copeland
      wrote on last edited by
      #2

      Just for anyone with a similar question in the future, I managed to resolve this quite simply. Upon the OnScroll event method, simply invalidate the BufferedGraphics object by disposing it, and reset it back to null. Invalidate the whole component, and when constructing the new BufferedGraphics object, set the targetRectangle parameter's X and Y values to the respective AutoScrollPosition values. Why this isn't mentioned elsewhere, I don't know.

      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