Re: Invalidating a region and having only that region drawn



Doug,

Thanks for your comment.

Andrew.

"Doug Forster" wrote:

> Hi Andrew,
>
> I could be wrong but I get the feeling you haven't fully understood what Bob
> was saying. You shouldn't be attempting to use clipping at all to manipulate
> the logical content of a window. The job of a paint handler is *just* to
> paint part or all of a window with the correct content of the moment as
> ascertained from state maintained external to the whole painting paradigm.
> You should remember that Windows itself can invalidate any part of your
> window at any time. This is not specific to .NET but is simply how Windows
> has always worked.
>
> Cheers
> Doug Forster
>
> "Andrew" <Andrew@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:18697CA9-3687-425F-8458-1E9FA99BAC84@xxxxxxxxxxxxxxxx
> > Thanks,
> >
> > I will need to rethink my drawing strategy paying closer attention to the
> > clipping region.
> >
> >
> > "Bob Powell [MVP]" wrote:
> >
> >> Painting works like this:
> >>
> >> The system stores the results of invalidate calls internally. Invalidate
> >> without parameters will mark a whole window for refreshing, invalidate
> >> with
> >> parameters will add regions to the list of "dirty" areas maintained by
> >> the
> >> system.
> >>
> >> When the queue is empty and there is nothing else to do, the system
> >> checks
> >> for dirty areas and issues a WM_PAINT message if any are found, otherwise
> >> it
> >> issues a WM_ENTERIDLE message to kick-off idle time processing.
> >>
> >> In all cases the result of the WM_PAINT message, for Windows Forms
> >> programs,
> >> is to run the OnPaint override which in turn kicks of the Paint event.
> >>
> >> The clipping region set in the OnPaint event arguments will be the sum of
> >> all the regions or the whole window depending on whether Invalidate was
> >> called without parameters.
> >>
> >> It's up to your code to either keep a list of its own dirty rectangles /
> >> regions OR to do output based on the bounds of the clipping region
> >> provided
> >> by the paint event arguments. Whatever paint strategies you devise, such
> >> as
> >> only drawing partial content or layers, is entirely up to you and needs
> >> to
> >> be managed by you. The system doesn't care about reporting anything
> >> except
> >> that there is an area of screen marked as being in need of a refresh.
> >>
> >> --
> >> Bob Powell [MVP]
> >> Visual C#, System.Drawing
> >>
> >> Find great Windows Forms articles in Windows Forms Tips and Tricks
> >> http://www.bobpowell.net/tipstricks.htm
> >>
> >> Answer those GDI+ questions with the GDI+ FAQ
> >> http://www.bobpowell.net/faqmain.htm
> >>
> >> All new articles provide code in C# and VB.NET.
> >> Subscribe to the RSS feeds provided and never miss a new article.
> >>
> >>
> >>
> >>
> >>
> >> "Andrew" <Andrew@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> >> news:B82AC0B1-5BFF-4867-A7A6-B8E0DB074432@xxxxxxxxxxxxxxxx
> >> > Hello,
> >> >
> >> > In my application I perform all the drawing operations from within the
> >> > form's
> >> > OnPaint method (the form is ultimately a TabPage derivative) ie
> >> >
> >> > protected override void OnPaint(PaintEventArgs e)
> >> > {
> >> > base.OnPaint(e);
> >> > //the base class LayerView.OnPaint handles things like
> >> > AutoScrollPosition
> >> > int s = 1; // temporary dummy scale value
> >> > m_building.DrawBuildingLayer(g,s,this.Name);
> >> > m_columns.DrawColumnsLayer(g,s,this.Name);
> >> > }
> >> >
> >> > The drawing works well and smoothly handles operations such as
> >> > scrolling.
> >> >
> >> > It is my understanding that when Invalidate() is called ie with no
> >> > parameters, the entire client area of the form is added to the update
> >> > region
> >> > and a paint message is sent that raises the Paint event which is
> >> > handled
> >> > by
> >> > the OnPaint handler. OK
> >> >
> >> > When Invalidate(region) is called, I believe that only that region is
> >> > added
> >> > to the form's update region resulting in only that region being redrawn
> >> > at
> >> > the next Paint message.
> >> >
> >> > Either way, calling Invalidate results in OnPaint to be executed.
> >> >
> >> > When I call Invalidate() the entire client area is redrawn with both
> >> > drawing
> >> > functions called and this is exactly the outcome that I want for that
> >> > scenario.
> >> >
> >> > The problem is that when I only want to redraw a invalidated region of
> >> > this
> >> > form,
> >> > the entire form is redrawn( which is causing objects to be appear
> >> > incorrectly).
> >> >
> >> > ie When I call Invalidate(with a specific region) in order to only have
> >> > that
> >> > region redrawn I do NOT intend for the likes of DrawBuildingLayer nor
> >> > DrawColumnsLayer
> >> > to be called. Obviously they are being called because of their presence
> >> > in
> >> > OnPaint().
> >> >
> >> > I cannot think of any other place where I could call these draw
> >> > functions
> >> > other than OnPaint and I want to steer clear of CreateGraphics.
> >> >
> >> > Are there any suggestions regarding a strategy of how I could call
> >> > Invalidate(region) and only have that region redrawn ?
> >> >
> >> >
> >> > Thanks
> >> >
> >> > Andrew.
> >> >
> >>
> >>
> >>
>
>
>
.



Relevant Pages

  • Re: Invalidating a region and having only that region drawn
    ... the logical content of a window. ... The job of a paint handler is *just* to ... You should remember that Windows itself can invalidate any part of your ... >> is to run the OnPaint override which in turn kicks of the Paint event. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Desktop using undocumented messages!
    ... both DCs point to the same HWND and both paint to it in at ... > Have you tried both the SHELL_DefView window and the SysListView32? ... when Windows builds a clipping region). ... > 3) Select the HBITMAP into a screen-compatible memory DC. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Here is BitBlt() drawing?
    ... if only half of your window is visible the clipping region prevents you from painting on some other window that is above yours. ... You can let MFC default the painting of the dialog, or you can paint it yourself, but you cannot do both. ...
    (microsoft.public.vc.mfc)
  • Re: Update on new paint job and leather seats - Trip back home
    ... we were occupied with inspecting the plane ... plane cover back on and to measure the pilot's side window but had to ... AOGPaint gave us some extra paint to paint the rivets for this new ... or not, the paint scheme was decided the last minute, the night before ...
    (rec.aviation.piloting)
  • Re: Invalidating a region and having only that region drawn
    ... resorting to CreateGraphicswhere else can I get a graphics object other ... called quite often (such as just after window creation, ... rectangles that represent the structural supports of the building outer. ... A. for the object selecting operation, I invalidate two ...
    (microsoft.public.dotnet.framework.drawing)