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
 
 
 
 
TitleMake a picture box with a hole in it
DescriptionThis example shows how to make a picture box with a hole in it in Visual Basic 6. It uses the API region functions to make a region with a hole in it and assigns the region to the PictureBox.
KeywordsPictureBox, shape, region, SetWindowRgn, shaped PictureBox
CategoriesAPI, Controls, Graphics
 
This example uses CreateRectRgn to make a region that includes the whole picture box. It uses CreateEllipticRgn to create a region in the center. It then uses CombineRgn to subtract the second region from the first and uses SetWindowRgn to restrict the picture box to the resulting region.
 
Private Sub Form_Resize()
Const RGN_DIFF = 4

Dim outer_rgn As Long
Dim inner_rgn As Long
Dim combined_rgn As Long
Dim wid As Single
Dim hgt As Single
Dim border_width As Single
Dim title_height As Single

    If WindowState = vbMinimized Then Exit Sub
    
    With picBox
        ' set the picture box to be measured in pixels
        .ScaleMode = vbPixels
        
        ' Create the regions.
        wid = .Width
        hgt = .Height
        outer_rgn = CreateRectRgn(0, 0, wid, hgt)
        
        border_width = (wid - .ScaleWidth) / 2
        title_height = hgt - border_width - .ScaleHeight
        inner_rgn = CreateEllipticRgn( _
            border_width + .ScaleWidth * 0.1, _
            title_height + .ScaleHeight * 0.1, _
            .ScaleWidth * 0.9, .ScaleHeight * 0.9)
    
        ' Subtract the inner region from the outer.
        combined_rgn = CreateRectRgn(0, 0, 0, 0)
        CombineRgn combined_rgn, outer_rgn, _
            inner_rgn, RGN_DIFF
        
        ' Restrict the picture box to the region.
        SetWindowRgn .hWnd, combined_rgn, True
    End With
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated