Question Getting the outline of a region...

tim8w

Active member
Joined
Oct 26, 2010
Messages
38
Programming Experience
5-10
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 highlight 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?
 
form created by setting the Region to an image
Care to elaborate on that?
 
I will guess you did something like this: Region from Bitmap

A Region object is pretty much the irreversible end of the line when it comes to the path/point information, but it possible to modify the Region object. I will present a way to shrink the form region using Matrix, center and exclude that from the clipping, then fill the form region. In effect drawing a border outline. This is for the forms paint event handler:
VB.NET:
Using rgn = Me.Region.Clone
    Using m As New Drawing2D.Matrix
        m.Scale(0.98, 0.98)                
        rgn.Transform(m)
    End Using            
    Dim s = Me.Region.GetBounds(e.Graphics).Size - rgn.GetBounds(e.Graphics).Size
    rgn.Translate(s.Width / 2, s.Height / 2)
    e.Graphics.ExcludeClip(rgn)
    e.Graphics.FillRegion(Brushes.Red, Me.Region)
End Using
 
John,
Not sure what additional information you are looking for. As I mentioned, I set the form's region to an irrregularly shaped image. When I do this, I lose all title bar functionality. I don't have a problem with that. I would like to let the user know when the form has focus and my thought was to draw a 2-pixel line around the edge of the form when the form is in focus and remove it (or change it's color) when it loses focus...
 
Back
Top