473,594 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SetStyle s(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 2968
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.Clien tSize.Width, Me.ClientSize.H eight)
dg.Buffer = m_buffer
End If

Dim g As Graphics = Graphics.FromIm age(m_buffer)
g.Clear(SystemC olors.Control)
g.Dispose()

'Copy the back buffer to the screen

e.Graphics.Draw ImageUnscaled(m _buffer, 0, 0)
End Sub

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

Protected Overrides Sub OnSizeChanged(B yVal e As EventArgs)
If Not (m_buffer Is Nothing) Then
m_buffer.Dispos e()
m_buffer = Nothing
End If

MyBase.OnSizeCh anged(e)
End Sub
The derived class
Public Class BufferedDataGri d
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(Contro lStyles.AllPain tingInWmPaint Or
ControlStyles.U serPaint Or ControlStyles.D oubleBuffer, True)
End Sub

Protected Overrides Sub OnPaint(ByVal pe As
System.Windows. Forms.PaintEven tArgs)
If m_buffer Is Nothing Then Return
Dim peArgs As New PaintEventArgs( Graphics.FromIm age(m_buffer),
pe.ClipRectangl e)
MyBase.OnPaint( peArgs)
End Sub

End Class

"Jamin Guy" <ja******@gmail .com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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()
{
InitializeCompo nent();

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

this.SetStyle(C ontrolStyles.Do ubleBuffer |ControlStyles. UserPaint |
ControlStyles.A llPaintingInWmP aint |
ControlStyles.R esizeRedraw, true);
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint (e);
Rectangle drawingRect = new Rectangle(new Point(xBuffer, yBuffer),
new Size(this.Clien tRectangle.Widt h - xBuffer,
this.ClientRect angle.Height - yBuffer));
e.Graphics.Draw String(this.Tex t, this.Font, new
SolidBrush(Colo r.DimGray), drawingRect);
}

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

}

protected override void OnTextChanged(E ventArgs e)
{
base.OnTextChan ged (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
3453
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 screen flicker a good bit while this happens. I'm using GDI+ and it say in MSDN that double buffering will fix this but it didnt work for me. this.Setstyle(Controlstyles.DoubleBuffer, true ); this.Setstyle(Controlstyles.UserPaint, true );...
1
3095
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 scrollable panel. Of course i've set right styles on a ChatControl: //styles this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
2
28764
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 the form as a whole. The following snippet makes compiler mad : this.DXPanel.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
2
5599
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 propagated to the groupbox, and since it's a protected method I can't call groupbox.SetStyle(). I've tried deriving a custom class from System.Windows.Forms.GroupBox and calling SetStyle from inside of it's constructor and from a new method. Both...
0
1376
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 alpha channel transparent one that windows xp's shell uses... is there any way to just keep the standard dotted rectangle one? because performance is slow when the transparent rectangle region is enabled with double buffering... but i cant find a way...
3
280
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 tried using myForm.SetStyles(ControlStyles.DoubleBuffer, True) however it has made no impact on the drawing operation. Any clarification would be greatly appreciated -Alex
7
6508
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 tried as a class doesnt work.. please please help. I only need the double buffering of controls, graphics... as a class. Can anyone help me with this? Thank You so so much in advacne. I would really appreciate any help.
1
1826
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 double-buffered property for the panel control. My first question: is the double buffering set on the form inherited by the panel control or do I have to do the old fashioned manual double-buffering with the panel? I've noticed that animation I render...
3
5941
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 when i add controls to this panel dyanamically, the double buffering effect is not there, i move all lines connceted to a control when the control is moved , at this time flickering occurs,also when i enable double buffering for a child control...
0
7947
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7880
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8010
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.