Results 1 to 16 of 16

Thread: BackBuffering ! =)

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    49

    BackBuffering ! =)

    Hi !

    Here's the Class for BackBuffering, It's easy. =)



    Code:
    Public Class IBackBuffer
        Private mvarBitmap As System.Drawing.Bitmap
        Private mvarBuffer As System.Drawing.Graphics
        Private mvarGraphics As System.Drawing.Graphics
        Private mvarForm As System.Windows.Forms.Form
    
        Public Sub Connect(ByVal xForm As System.Windows.Forms.Form)
            mvarForm = xForm
            mvarGraphics = mvarForm.CreateGraphics
            mvarBitmap = New Bitmap(mvarForm.Width, mvarForm.Height)
            mvarBuffer = Graphics.FromImage(mvarBitmap)
        End Sub
    
        Public ReadOnly Property Graphics() As System.Drawing.Graphics
            Get
                Return mvarBuffer
            End Get
        End Property
    
        Public Sub DoPainting()
            mvarGraphics.DrawImage(mvarBitmap, 0, 0)
        End Sub
    End Class

    This is how you use it:

    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim xBackBuffer As New IBackBuffer()
    
            'Connect BackBuffer Component to Form1
            xBackBuffer.Connect(Form1)
    
            '#############################
            'Do Your Graphics Drawing Here
            '#############################
            'You Draw you graphics using xBackBuffer.Graphics
            'xBackBuffer.Graphics.*
            '#############################
    
            'Finally, Flicker Free paint your graphics.
            xBackBuffer.DoPainting()
        End Sub
    There you go. =)

    Thank you, [KeLi F.K.A Zleepy].

    Homepage: http://fraxionsoftware.cjb.net
    ICQ: 40269591
    Mail: [email protected]

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    that's cool ,yeah cool .
    what does it do btw?? .lol

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    ooh that was related to the other post I guess . Thanx anyways .

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i am trying to put a owner drawn item in a panel that draws a progressbar......then i do some text proccessing and i want to use it...the problem is that when i use the progress bar in it the text work gets like 30% slower and even worse the panel progressbar flickers a lot! how do i prevent it from flickering?
    \m/\m/

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Are you drawing the ProgressBar (overriding the Paint event)?

    If so, you should be able to do "double-buffering"...

    Look up ControlStyles in your help index... and look for DoubleBuffering.

    Me.SetStyles(ControlStyles.AllPaintinginWMPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

  7. #7
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yes im going read it but in the mean time i have the following method of the status bar im inheriting:
    Code:
    protected override void OnDrawItem(StatusBarDrawItemEventArgs e) {
    if (e.Panel.Style == StatusBarPanelStyle.OwnerDraw) {
    Graphics g = e.Graphics;
    g.FillRectangle(new SolidBrush(SystemColors.ActiveCaptionText),
    e.Bounds.X,
    e.Bounds.Y,
    GetPercentage(e.Bounds.Width),
    e.Bounds.Height);
    base.OnDrawItem (e);
    }
    }
    sorry because its in c# but what should i change here? i tried to put ut string in the begginig and when i tried it the progress bar just shown ALL in the same color(the default one) without showing any panel
    \m/\m/

  8. #8
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    bah the drawning error was my fault when converting the vb.net string to c# string....now it works but it does not any double buffering(at least it still flickers a lot)

    what am i suposed to do?
    \m/\m/

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Ok, are you writing in C# or VB?

  10. #10
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    c# but u can say things in vb.net or c# its the same i understand them boot lol
    \m/\m/

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Egh.. alright. Problems can arise because you have a form, a status bar, and a progress bar. So you basically have 3 controls that may at some point redraw themselves, and may invalidate themselves.

    But from what I understand, you are invalidating just the progressbar, because you are writing text to its center, correct?

    If so, the only real way I could help is to be able to look at that control class's source. And of course, if you are using .Net 2003, I probably will be out of luck.

    So, try putting this in your progressbar constructor.

    Code:
    // Set the value of the double-buffering style bits to true.
       this.SetStyle(ControlStyles.DoubleBuffer | 
          ControlStyles.UserPaint | 
          ControlStyles.AllPaintingInWmPaint,
          true);
       this.UpdateStyles();
    Here's a reference... http://msdn.microsoft.com/library/de...styletopic.asp

    http://msdn.microsoft.com/library/de...classtopic.asp

    http://msdn.microsoft.com/library/de...ncontrols7.asp
    Last edited by nemaroller; Sep 11th, 2003 at 09:33 AM.

  12. #12
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    well i tried and it just doesnt paint all the status bar
    \m/\m/

  13. #13
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Could you upload the source for your progressbar?

  14. #14
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    here..
    Attached Images Attached Images  
    \m/\m/

  15. #15
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm the project is a bit complex for me to upload but i can show the progressbar code:

    Code:
    	public class ProgressBarStatusBar : StatusBar {
    		private int _progress = 0;
    		public int Progress {
    			get { return _progress;
    			} set {
    				  if (value >= 0 && value <= 100) {
    					  _progress = value;
    					  Refresh();
    				  }
    			  }
    		}
    
    		public ProgressBarStatusBar() {
    			SetStyle(ControlStyles.AllPaintingInWmPaint |
    				ControlStyles.UserPaint |
    				ControlStyles.DoubleBuffer, true);
    			UpdateStyles();
    		}
    
    		protected override void OnDrawItem(StatusBarDrawItemEventArgs e) {
    			if (e.Panel.Style == StatusBarPanelStyle.OwnerDraw) {
    				Graphics g = e.Graphics;
    				g.FillRectangle(new SolidBrush(SystemColors.ActiveCaptionText),
    					e.Bounds.X,
    					e.Bounds.Y,
    					GetPercentage(e.Bounds.Width),
    					e.Bounds.Height);
    
    				base.OnDrawItem (e);
    			}
    		}
    
    		private int GetPercentage(int panelSize) {
    			return Convert.ToInt32(
    				(double)panelSize * (double)_progress / (double)100);
    		}
    	}
    }
    then..just add a statusbar to ur form and add an owner drawn item.
    to put a value to the progressbar do the following:
    ((StatusBarProgressBar)statusBar1).Progress = 50;
    \m/\m/

  16. #16
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    bump
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width