form in polygon shape 
Author Message
 form in polygon shape

In vb6 I was able to create a form with a shape of a polygon using some
APIs.
In vb.net the APIs can not be used because the property "handle" is not the
same as "hWnd" and can not be casted. Can anyone tell me what to do?


Fri, 22 Oct 2004 20:20:37 GMT  
 form in polygon shape

Quote:

> In vb6 I was able to create a form with a shape of a polygon using
> some APIs.
> In vb.net the APIs can not be used because the property "handle" is
> not the same as "hWnd" and can not be casted. Can anyone tell me what
> to do?

You need to create a new Region and set that to be the region of your form.
. . .Here is an example:

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim grphSurface As Graphics
        Dim grphPath As GraphicsPath = New GraphicsPath()
        Dim rgnSurface As Region
        Dim rectText As RectangleF
        Dim fntText As Font
        Dim XPoints1(3) As PointF
        Dim XPoints2(3) As PointF

        Me.BackColor = Color.Goldenrod

        XPoints1(0) = New PointF(10, 0)
        XPoints1(1) = New PointF(0, 10)
        XPoints1(2) = New PointF(Me.Width - 10, Me.Height)
        XPoints1(3) = New PointF(Me.Width, Me.Height - 10)

        XPoints2(0) = New PointF(Me.Width - 10, 0)
        XPoints2(1) = New PointF(Me.Width, 10)
        XPoints2(2) = New PointF(10, Me.Height)
        XPoints2(3) = New PointF(0, Me.Height - 10)

        grphPath.AddEllipse(Me.ClientRectangle)
        rgnSurface = New Region(grphPath)
        Me.Region = rgnSurface

        With Me.ClientRectangle
            rectText = New RectangleF(.X + 3, .Height \ 3, .Width + 3,
.Height \ 2)
        End With
        fntText = New Font(Me.Font.FontFamily, 55, FontStyle.Bold)
        grphSurface = Me.CreateGraphics

        grphSurface.DrawEllipse(New Pen(Color.Black, 10),
Me.ClientRectangle)
        grphSurface.FillPolygon(New SolidBrush(Color.Black), XPoints1)
        grphSurface.FillPolygon(New SolidBrush(Color.Black), XPoints2)
        grphSurface.DrawString("R        R", fntText, New
SolidBrush(Color.Black), rectText)

        fntText.Dispose()
        grphSurface.Dispose()
        grphPath.Dispose()
        rgnSurface.Dispose()
    End Sub

--
Jacob Grass
Microsoft .NET MVP
Check out http://windowsforms.net



Fri, 22 Oct 2004 22:23:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. I can make form in any shape(round, polygon, ellipse, etc)

2. DirectX 9 - Draw Simple 2D Polygon / Shape

3. Shapes / Polygons

4. Adding a shape from Forms Shapes Stencil

5. polygon - polygon intersection

6. Shapes shapes shapes

7. Creating Polygon Forms - Lost Web Site!

8. new shape in another shape

9. How to differentiate a shape created from Stencil drag/drop and shape Copy/Paste

10. How to update document master shapes from template master shapes

11. Dynamically convert shapes to Process Engineering shapes

12. Dropping shapes through VBA with shape Custom Properties setting ASK =True

 

 
Powered by phpBB® Forum Software