OnPaint and Device Context`

Dick Donny

New member
Joined
Aug 31, 2004
Messages
2
Location
South Yorkshire, England
This is probably a really simple thing to fix (must be a very common issue) but Im struggling to figure out what to do ... hope you can help.

On a Paint event I am creating a bitmap that scales to the full drawing rect. It all works ok until the rect is increased in size (and then is ok sometimes and not others)

It appears the device context is doing something behind the scenes to determine that it actually does not need to draw a specific part of the returned bitmap, however, the paint event is fired via an Invalidate call as opposed to a window being dragged over it, so not sure how it has determined what to draw and what not to draw.

Anyway, the result it that when the rect space increases, part of the rect is not redrawn, and a bit of the old bitmap is still visible. Ive enclosed a screen shot to show what I mean.

Ive been looking at the translatetransform procedure, but Im not sure if this is the right approach.

Any help would be appreciated. This is my code if its of any use.


e.Graphics.Clear(m_canvas.BackColor)

Dim rect As New Rectangle(New Point(0, 0), m_canvas.Size)
Dim db As New RA.Utilities.Drawing.Drawing2D.GraphicsDoubleBuffer(rect)

db.Store()

m_renderer.Paint(db.Store, rect)

e.Graphics.DrawImage(db.Canvas, rect)

db.Dispose()


Shown above is the code I use in the actual paint event of the picture box (m_canvas). m_renderer is an interface into an object that exposes a Paint method. This method always draws a bitmap for the passed rect, which is the full size of the picture box. db is just a double buffering class I use.

Thanks in advance of any help you can offer.
 
Same again i think. For some reason the paint even is not called when a control is resized. I think standard controls must call the paint event explicitly. I had this problem with my GDI buttons. It was ok if i enlarged the control but went nuts if i tried to reduce the size. And sometimes there were residue bits of the old image. I solved it by a simple me.refresh in the controls resize event.

Dill
 
Dill said:
Same again i think. For some reason the paint even is not called when a control is resized. I think standard controls must call the paint event explicitly. I had this problem with my GDI buttons. It was ok if i enlarged the control but went nuts if i tried to reduce the size. And sometimes there were residue bits of the old image. I solved it by a simple me.refresh in the controls resize event.

Dill

Thanks for that, but its not the same issue.

Your problem is because when a control is reduced in size, the control does not believe it needs to repaint (it already has the reduced region paint). You need to post a me.invalidate(rect) message and itll work fine.
 
Back
Top