Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How do I create/cut a circular hole in VB.NET 2010?
Posted
Updated 30-May-14 8:06am
v2
Comments
Thomas Daniels 30-May-14 13:00pm    
Windows Form, or WPF?

1 solution

You haven't specified whether you use Windows Forms or WPF, but because you talk about a "Form", I assume you use Windows Forms.

First, add this to the top of your code file:
VB
Imports System.Drawing.Drawing2D

And to make a hole, do this:
VB
Dim hole As New GraphicsPath()
Dim x As Integer = 0
Dim y As Integer = 0
Dim width As Integer = 100
Dim height As Integer = 100
hole.AddEllipse(x, y, width, height)
Dim formRegion As New Region(New Rectangle(Point.Empty, Me.Size))
formRegion.Exclude(hole)
Me.Region = formRegion

Note that this has a side effect: after setting a value to Me.Region, the style of the form border changes.
 
Share this answer
 
Comments
Aarti Meswania 30-May-14 13:25pm    
nice solution.
5+! :)
Thomas Daniels 30-May-14 13:30pm    
Thank you!
Member 14822466 17-May-20 10:26am    
is there any way to create a hole without causing the original form1 to change, thank you
Member 14822466 17-May-20 10:29am    
thank you for the solution for makeing holes but it really stands out because of the border lining , it was nice if it used the same format without changing the look of the original form, thank u
Thomas Daniels 17-May-20 10:29am    
I don't know, sorry.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900