Re: GDI+ error when trying to use DoubleBuffer

From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 05/29/04


Date: Sat, 29 May 2004 11:36:38 +0200

Hello Chris.

Did you subscribe to the Windows Forms Tips and Tricks RSS feed? If you did
you'll have discovered that the article has been updated to include code in
VB.NET.

I reccommend RSS Bandit if you haven't already chosen an RSS aggregator yet.

-- 
Bob Powell [MVP]
Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
"Chris" <joe@mail.com> wrote in message
news:%23DbH2rTREHA.3012@tk2msftngp13.phx.gbl...
> The code is in C# which I am not familiar with.  I have tried to convert
it
> but have been unsuccessfull.  Could someone help me find or write the
VB.NET
> version of double buffering?
>
>
> Thanks!
> Chris
>
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:ukf6z%23HREHA.1548@TK2MSFTNGP10.phx.gbl...
> > I have noticed this same exception on several occasions and I beleive
> there
> > is a bug in Windows Forms double buffer code but I cannot say exactly
> what's
> > needed to reproduce the fault.
> >
> > To fix the problem in one of my applications that blows up regularly
with
> > this problem I used manula double buffering.
> >
> > The Windows Forms Tips and Tricks page has an article on double
buffering
> > that illustrates how to do this.
> >
> > http://www.bobpowell.net/tipstricks.htm
> >
> > -- 
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Image transition effects, automatic persistent configuration and
> > design time mouse operations all in April's issue of Well Formed
> > http://www.bobpowell.net/wellformed.htm
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/gdiplus_faq.htm
> >
> > The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
> > Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tipstricks.xml
> > Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
> >
> >
> >
> >
> >
> > "Chris" <joe@mail.com> wrote in message
> > news:Oezuy9GREHA.2876@TK2MSFTNGP09.phx.gbl...
> > > When I run this code I get this error.  If I comment out DoubleBuffer,
> the
> > > program works fine.  Can anyone figure out why it is failing?
> > >
> > > Error message:
> > > An unhandled exception of type 'System.ArgumentException' occurred in
> > > system.drawing.dll
> > > Additional information: Invalid parameter used.
> > >
> > > Code:  (This code works if you put it into a new application and add a
> > > timer.  Also import System.Drawing.Drawing2D)
> > >
> > > Dim RotAng As Decimal = 1.0F
> > > Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
> > > System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
> > >
> > > Dim canvas As Graphics = e.Graphics
> > >
> > > Dim paintBrush As New SolidBrush(Color.Black)
> > >
> > > Dim pen1 As New Pen(Color.Black)
> > >
> > > Dim gpath As New GraphicsPath
> > >
> > > Dim XPoints1(3) As PointF
> > >
> > > XPoints1(0) = New PointF(6, 6)
> > >
> > > XPoints1(1) = New PointF(0, 6)
> > >
> > > XPoints1(2) = New PointF(0, 9)
> > >
> > > XPoints1(3) = New PointF(6, 9)
> > >
> > > Dim myMatrix As New Matrix
> > >
> > > Dim myMatrix2 As New Matrix
> > >
> > > Dim rotatePoint As New PointF(3.0F, 7.5F)
> > >
> > > myMatrix.RotateAt(RotAng, rotatePoint, MatrixOrder.Append)
> > >
> > > gpath.AddPolygon(XPoints1)
> > >
> > > gpath.Transform(myMatrix)
> > >
> > > myMatrix2.Translate(50, 50)
> > >
> > > myMatrix2.Scale(4, 4)
> > >
> > > gpath.Transform(myMatrix2)
> > >
> > >
> > >
> > > 'e.Graphics.FillPath(paintBrush, gpath)
> > >
> > > e.Graphics.DrawPath(pen1, gpath)
> > >
> > > paintBrush.Dispose()
> > >
> > > pen1.Dispose()
> > >
> > > canvas.Dispose()
> > >
> > > RotAng = RotAng + 3.0F Mod 360.0
> > >
> > > End Sub
> > >
> > > Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
> > > System.EventArgs) Handles MyBase.Resize
> > >
> > > Invalidate()
> > >
> > > End Sub
> > >
> > > Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles Timer1.Tick
> > >
> > > Me.Invalidate()
> > >
> > > End Sub
> > >
> > > Private Sub Form1_Load(ByVal sender As Object, ByVal e As
> > System.EventArgs)
> > > Handles MyBase.Load
> > >
> > > Me.SetStyle(ControlStyles.DoubleBuffer, True)
> > >
> > > Me.SetStyle(ControlStyles.UserPaint, True)
> > >
> > > Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
> > >
> > > Me.UpdateStyles()
> > >
> > > End Sub
> > >
> > >
> > >
> > > This code rotates a simple box drawn with a graphics path and pen.
> > >
> > > Thanks!
> > >
> > > Chris
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Bob Powells Beginners Guide to GDI+
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... Subscribe to the RSS feeds provided and never miss a new article. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Bob Powells Beginners Guide to GDI+
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... Subscribe to the RSS feeds provided and never miss a new article. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Bob Powells Beginners Guide to GDI+
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... Subscribe to the RSS feeds provided and never miss a new article. ...
    (microsoft.public.dotnet.framework)
  • Re: Bob Powells Beginners Guide to GDI+
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... Subscribe to the RSS feeds provided and never miss a new article. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Bob Powells Beginners Guide to GDI+
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... Subscribe to the RSS feeds provided and never miss a new article. ...
    (microsoft.public.dotnet.framework.windowsforms)