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. custom double buffering [modified]

custom double buffering [modified]

Scheduled Pinned Locked Moved C#
graphics
7 Posts 3 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.
  • H Offline
    H Offline
    HexaDeveloper
    wrote on last edited by
    #1

    public void tab_Paint(object sender, PaintEventArgs e) { TabPage tab = (TabPage)sender; BufferedGraphicsContext context; BufferedGraphics buffer; // context = BufferedGraphicsManager.Current; /// Dedicated context /// used when highly animated graphics context = new BufferedGraphicsContext(); Graphics grfx = e.Graphics; buffer = context.Allocate(grfx, tab.ClientRectangle); // draw to the buffer drawSurfaceToBuffer(buffer.Graphics); // draw the buffer to the screen buffer.Render(grfx); buffer.Dispose(); grfx.Dispose(); } public void drawSurfaceToBuffer(Graphics bufferGrfx) { /// some processing that used the buffer grfxs } this code i understand it from MSDN and write it to reduce Graphics Flicker but it does not make any thing at all also it make my background of tabpage black and the original is white is there any suggestions please Generator -- modified at 10:59 Tuesday 1st May, 2007

    I L 2 Replies Last reply
    0
    • H HexaDeveloper

      public void tab_Paint(object sender, PaintEventArgs e) { TabPage tab = (TabPage)sender; BufferedGraphicsContext context; BufferedGraphics buffer; // context = BufferedGraphicsManager.Current; /// Dedicated context /// used when highly animated graphics context = new BufferedGraphicsContext(); Graphics grfx = e.Graphics; buffer = context.Allocate(grfx, tab.ClientRectangle); // draw to the buffer drawSurfaceToBuffer(buffer.Graphics); // draw the buffer to the screen buffer.Render(grfx); buffer.Dispose(); grfx.Dispose(); } public void drawSurfaceToBuffer(Graphics bufferGrfx) { /// some processing that used the buffer grfxs } this code i understand it from MSDN and write it to reduce Graphics Flicker but it does not make any thing at all also it make my background of tabpage black and the original is white is there any suggestions please Generator -- modified at 10:59 Tuesday 1st May, 2007

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      I think this code is meant to reduce flicker for user-painted graphics. If you're just putting controls onto the tabpage and seeing flickering whenever you move/resize, this code won't help you at all, and might actually slow you down. You might just have too many controls, which leads to too much layout logic. I would suggest trying to limit the number of controls and nested containers. For instance, putting panels inside panels inside panels, each with their own anchors, docks, and layout engines, will really slow you down whenever you resize.

      1 Reply Last reply
      0
      • H HexaDeveloper

        public void tab_Paint(object sender, PaintEventArgs e) { TabPage tab = (TabPage)sender; BufferedGraphicsContext context; BufferedGraphics buffer; // context = BufferedGraphicsManager.Current; /// Dedicated context /// used when highly animated graphics context = new BufferedGraphicsContext(); Graphics grfx = e.Graphics; buffer = context.Allocate(grfx, tab.ClientRectangle); // draw to the buffer drawSurfaceToBuffer(buffer.Graphics); // draw the buffer to the screen buffer.Render(grfx); buffer.Dispose(); grfx.Dispose(); } public void drawSurfaceToBuffer(Graphics bufferGrfx) { /// some processing that used the buffer grfxs } this code i understand it from MSDN and write it to reduce Graphics Flicker but it does not make any thing at all also it make my background of tabpage black and the original is white is there any suggestions please Generator -- modified at 10:59 Tuesday 1st May, 2007

        L Offline
        L Offline
        LongRange Shooter
        wrote on last edited by
        #3

        In the 2.0 Framework there was a lot of work incorporating Double Buffering into the framework. For the form that holds the flickering control, try adding this at initialization time:

        		this.SetStyle( ControlStyles.OptimizedDoubleBuffer );
        		this.SetStyle( ControlStyles.AllPaintingInWmPaint );
        

        These two settings go hand-in-hand. Also when loading controls on the tab,

                            this.TabControl.SuspendLayout();
                            LoadControl(TabControl);
                            this.TabControl.ResumeLayout();
        
        H 1 Reply Last reply
        0
        • L LongRange Shooter

          In the 2.0 Framework there was a lot of work incorporating Double Buffering into the framework. For the form that holds the flickering control, try adding this at initialization time:

          		this.SetStyle( ControlStyles.OptimizedDoubleBuffer );
          		this.SetStyle( ControlStyles.AllPaintingInWmPaint );
          

          These two settings go hand-in-hand. Also when loading controls on the tab,

                              this.TabControl.SuspendLayout();
                              LoadControl(TabControl);
                              this.TabControl.ResumeLayout();
          
          H Offline
          H Offline
          HexaDeveloper
          wrote on last edited by
          #4

          hi , i can not find a method called LoadControl() thanx Generator

          L 1 Reply Last reply
          0
          • H HexaDeveloper

            hi , i can not find a method called LoadControl() thanx Generator

            L Offline
            L Offline
            LongRange Shooter
            wrote on last edited by
            #5

            :laugh: That was just shorthand in the example. :laugh: That is where you are loading the controls into the new tab. Basically you suspend layout, load the controls, resumelayout and then the TabControl displays the controls all at once. Did you ever look at the Window Generated code for a form??? Look at it. This is what is standard code when a design-time-generated form is populated. Look at the code as an example and follow it. :cool:

            H 1 Reply Last reply
            0
            • L LongRange Shooter

              :laugh: That was just shorthand in the example. :laugh: That is where you are loading the controls into the new tab. Basically you suspend layout, load the controls, resumelayout and then the TabControl displays the controls all at once. Did you ever look at the Window Generated code for a form??? Look at it. This is what is standard code when a design-time-generated form is populated. Look at the code as an example and follow it. :cool:

              H Offline
              H Offline
              HexaDeveloper
              wrote on last edited by
              #6

              hi , ok i looked at the generated code but i use setstyle before and no change on tab just change on form so what can i do explain please "Iam sorry but i didnot get the point" Generator -- modified at 3:35 Saturday 5th May, 2007 Generator

              H 1 Reply Last reply
              0
              • H HexaDeveloper

                hi , ok i looked at the generated code but i use setstyle before and no change on tab just change on form so what can i do explain please "Iam sorry but i didnot get the point" Generator -- modified at 3:35 Saturday 5th May, 2007 Generator

                H Offline
                H Offline
                HexaDeveloper
                wrote on last edited by
                #7

                hi all, first thanx for ur help second a friend to me solve our problem of double buffered as follows class customTabPage : TabPage { customTabPage():base() { this.DoubleBuffered = true; } } Generator

                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