Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCreate an elliptical form
Keywordsform, shape, region, SetWindowRgn, shaped form, ellipse, elliptical
CategoriesTips and Tricks, Graphics
 
Use the CreateEllipticRgn API function. Then use SetWindowRgn to restrict the form to the resulting region.

This program makes the ellipse big enough to include pieces of the form's borders so you can resize the form. The program rebuilds the ellipse whenever the form is resized.

 
Private Sub Form_Resize()
Dim rgn As Long
Dim wid As Single
Dim hgt As Single

    If WindowState = vbMinimized Then Exit Sub

    ' Create the elliptical region.
    wid = ScaleX(Width, vbTwips, vbPixels)
    hgt = ScaleY(Height, vbTwips, vbPixels)
    rgn = CreateEllipticRgn(0, 0, wid, hgt)

    ' Restrict the window to the region.
    SetWindowRgn hWnd, rgn, True
    DeleteObject rgn

    Command1.Move _
        (ScaleWidth - Command1.Width) / 2, _
        (ScaleHeight - Command1.Height) / 2
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated