Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the outline of a region...

Status
Not open for further replies.

Tim8w

Programmer
Apr 8, 2003
44
US
I have a custom-shaped form created by setting the Region to an image. I want to be able to highlight the edge of the form when it has focus. To do this I believe I need to get the outline of the form and convert it to a path so I can draw a two-pixel gihlight around the edge of the form.

(1) Is this the correct approach?
(2) If so, how do I get the outline of the region so I can call DrawPath?
 

Is it possible to slightly enlarge the form/region, so it "sticks out" past the edge of the image? If so, you could do this, then color the entire form with the highlight color. The only visible part will be what sticks out past the image, which will provide the highlight.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
>created by setting the Region to an image

How are you doing this? I ask because it may be possible to modify this to create a path instead and then convert that path to a region, which is easy, rather than start with a region and convert to a path - which is basically rather hard (regions consist of a merged set of rectangles which are difficult to convert back in to an outline path)

An alternative technique might be to apply a resizing transform to the region and then use it as a clip rgn that you paint into (similarly to jebenson's suggestion).
 
In fact, here's a quick example of the latter technique. It requires a form with a picturebox and command button. Then jsut copy in thwe following code:
Code:
[blue]    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim g As Graphics = Me.PictureBox1.CreateGraphics() [green]'work against a picturebox for this example

        ' the lines below just create us a region called myregion[/green]
        Dim path As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath
        path.AddEllipse(New Rectangle(0, 0, 100, 100))
        Dim myregion As Region = New System.Drawing.Region(path)

        Using rgn = myregion.Clone

            [green]' Make the cloned region slightly bigger than the original[/green]
            Using m As New Drawing2D.Matrix
                m.Scale(1.02, 1.02)
                rgn.Transform(m)
            End Using

            [green]' Recenter the larger clone[/green]
            Dim s = myregion.GetBounds(g).Size - rgn.GetBounds(g).Size
            rgn.Translate(s.Width / 2, s.Height / 2)

            [green]' Ok, paint a picture into myregion, in this case just a simple fill of the region which happens to be an ellipse[/green]
            g.FillRegion(Brushes.White, myregion)

            [green]' Now exclude the original region from the clipping region[/green]
            g.ExcludeClip(myregion)

            [green]' Now paint in the bigger region - because we have removed original region from clipping area and recentered the slightly larger clone we will only see an outline painted[/green]
            g.FillRegion(Brushes.Black, rgn)

        End Using

        [green]' Tidy up[/green]
        g.Dispose()
    End Sub[/blue]

Remember this is merely an illustration of the technique, not a full solution
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top