473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

double buffering a windows form

I have read plenty about applying double buffering for animation and self
drawn forms. Is there a way to apply it to a form with many standard
controls on it (textboxes, labels etc) ?? I have tried using
myForm.SetStyles(ControlStyles.DoubleBuffer, True) however it has made no
impact on the drawing operation. Any clarification would be greatly
appreciated

-Alex
Jul 21 '05 #1
3 2936
http://www.bobpowell.net/doublebuffer.htm

Double buffering will only affect the Form.OnPaint method, which you
will have to override if you use the techniques described in the link
above. The controls on your form all have their own OnPaint methods,
which have nothing to do with the form's double buffering. You would
have to implement double buffering on each individual control...

Jul 21 '05 #2
I tried implementing double buffering on a single control without success.
Any idea what im missing here? The datagrid no longer paints at all, its
just a black box.

The form event
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If m_buffer Is Nothing Then
m_buffer = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
dg.Buffer = m_buffer
End If

Dim g As Graphics = Graphics.FromImage(m_buffer)
g.Clear(SystemColors.Control)
g.Dispose()

'Copy the back buffer to the screen

e.Graphics.DrawImageUnscaled(m_buffer, 0, 0)
End Sub

Protected Overrides Sub OnPaintBackground(ByVal pevent As
PaintEventArgs)
'Don't allow the background to paint
End Sub

Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
If Not (m_buffer Is Nothing) Then
m_buffer.Dispose()
m_buffer = Nothing
End If

MyBase.OnSizeChanged(e)
End Sub
The derived class
Public Class BufferedDataGrid
Inherits DataGrid

Private m_buffer As Bitmap

Public Property Buffer() As Bitmap
Get
Return m_buffer
End Get
Set(ByVal Value As Bitmap)
m_buffer = Value
End Set
End Property

Public Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint Or
ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
End Sub

Protected Overrides Sub OnPaint(ByVal pe As
System.Windows.Forms.PaintEventArgs)
If m_buffer Is Nothing Then Return
Dim peArgs As New PaintEventArgs(Graphics.FromImage(m_buffer),
pe.ClipRectangle)
MyBase.OnPaint(peArgs)
End Sub

End Class

"Jamin Guy" <ja******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
http://www.bobpowell.net/doublebuffer.htm

Double buffering will only affect the Form.OnPaint method, which you
will have to override if you use the techniques described in the link
above. The controls on your form all have their own OnPaint methods,
which have nothing to do with the form's double buffering. You would
have to implement double buffering on each individual control...

Jul 21 '05 #3
I'm not sure if you can make a custom drawn DataGrid, but here is an
example of a custom StatusBar that I double-buffered.

public class StatusBarEx : StatusBar
{
private int xBuffer = 4, yBuffer = 4;

public StatusBarEx()
{
InitializeComponent();

//
// TODO: Add constructor logic here
//

this.SetStyle(ControlStyles.DoubleBuffer |ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw, true);
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
Rectangle drawingRect = new Rectangle(new Point(xBuffer, yBuffer),
new Size(this.ClientRectangle.Width - xBuffer,
this.ClientRectangle.Height - yBuffer));
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(Color.DimGray), drawingRect);
}

private void InitializeComponent()
{
//
// StatusBarEx
//
this.Font = new System.Drawing.Font("Arial", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));

}

protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged (e);

this.Refresh();
}

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason | last post by:
I have created a 2d isometric game map using tiles and now I'm trying to move around my map..when i go near the edge of the map I want to redraw the map to show new parts of the map however the...
1
by: Kuba Florczyk | last post by:
Hi I've got some problem doing double buffer. Here is my problem: I've got custom control on which i paint some data (chat messages, lets call it ChatControl), this control is puted on a...
2
by: Millennium Falcon | last post by:
Hi! In my application, I have a panel in the middle of the form, which I'll be using as a drawing panel. I would like to update the drawing panel each time when it is required, without updating...
2
by: Dan Neely | last post by:
My dialog has groupboxes with slow to redraw controls, to improve the appearance I want to doublebuffer it. While I can use SetStyle() in the Dailogs constructor the setting change doesn't get...
0
by: Brian Henry | last post by:
I am trying to do a owner drawn list view in detail mode, when i inherited the list view into a new custom control then turned on double buffering all the sudden the selection rectangle is the...
3
by: Alex Glass | last post by:
I have read plenty about applying double buffering for animation and self drawn forms. Is there a way to apply it to a form with many standard controls on it (textboxes, labels etc) ?? I have...
7
by: Rain | last post by:
Hello Gurus! I really need this one to finish a module in my thesis. PLease please help me. I need a double buffer class so i can call it and use it anytime i want, the problem is everything ive...
1
by: TyBreaker | last post by:
I notice in VB 2005 that I can set a form to be double-buffered just by setting that option to true in the Form properties. I have a panel on that form but there doesn't appear to be a...
3
by: ssoffline | last post by:
hi i have an app in which i can drop objects onto a form and move them, it consists of graphics (lines), i am using double buffering to avoid filckering in the parent control which is a panel,but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.