"Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region
"Append rectangles" to Region "Append rectangles" to Region
"Append rectangles" to Region
Go Back  Xtreme Visual Basic Talk > > > "Append rectangles" to Region


Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2011, 05:57 PM
WhatsMyUsername's Avatar
WhatsMyUsername WhatsMyUsername is offline
Regular
 
Join Date: Jan 2011
Location: Currently? Costa Rica
Posts: 52
Default "Append rectangles" to Region


Invalidate(Region) will invalidate a.... well... region. Yes.

This is quite useful, and there's something that would make my life much easier: Append rectangles to a region.

You see, you can create a Region by using a Rectangle as parameter. But what if I wanted many rectangles? Add more rectangles to the Region later?

Normally:
Code:
Dim r As Region = New Region(rect1)
Me.Invalidate(r)
Invalidates whatever is inside rect1 in my Form

But what I want is something like...
Code:
Dim r As Region = New Region(rect1)
r.AppendRectangle(rect2)
r.AppendRectangle(rect3)
Me.Invalidate(r)
Invalidates whatever is inside rect1, rect2 and rect3 in my Form



So, is that possible? Thanks ~


Edit: Now that I think of it, what is the difference between a Region and a Rectangle? Maybe the "append" feature I mentioned? XD
Reply With Quote
  #2  
Old 01-17-2011, 09:45 PM
AtmaWeapon's Avatar
AtmaWeapon"Append rectangles" to Region AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I think the Region.Union() method is what you want. I don't believe this will always represent a rectangular region, but I'm struggling to come up with a way to test that.

Update:
Here we go:
Code:
Public Class Form1

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        Dim firstRect As New Rectangle(10, 10, 50, 50)
        Dim secondRect As New Rectangle(100, 100, 50, 50)

        Using rgn As New Region(firstRect)
            rgn.Union(secondRect)

            e.Graphics.FillRegion(Brushes.Blue, rgn)
        End Using
    End Sub

End Class
That fills one region, but appears to fill two different rectangles. That may or may not be tough to deal with from a drawing algorithm; I haven't ever tried to mess with a discontinuous invalidation region. It's probably best to get the entire bounds of the region in that case, but there may be something clever you can do with the Region itself.

Quote:
Edit: Now that I think of it, what is the difference between a Region and a Rectangle? Maybe the "append" feature I mentioned? XD
Rectangle is a lightweight structure that stores 4 integer values and represents a rectangular shape. Region looks like it's more or less a .NET version of the GDI+ Region construct. This has a GDI handle and is thus more heavyweight (it implements IDisposable; that's the big hint that you don't want to casually create them.) Regions aren't limited to rectangular areas either, nor (I think) do they have to be continuous.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.

Last edited by AtmaWeapon; 01-17-2011 at 09:52 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
"Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region "Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region "Append rectangles" to Region
"Append rectangles" to Region
"Append rectangles" to Region
 
"Append rectangles" to Region
"Append rectangles" to Region
 
-->