make a hole in a form??

how do I creat a hole in a form??
Micki-WeaverAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
"but VB is ok"

Here is a hard coded "hole" in a form...

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim gp As New System.Drawing.Drawing2D.GraphicsPath

        ' start with a rectangle that represents the whole form
        gp.AddRectangle(New Rectangle(0, 0, Me.Width, Me.Height))

        ' add an ellipse...which is removed from the rectangle above
        Dim w As Integer = Me.Width / 4
        Dim h As Integer = Me.Height / 4
        gp.AddEllipse(New Rectangle(w, h, w * 2, h * 2))

        ' create a Region from the GraphicsPath and set it...
        Me.Region = New Region(gp)
    End Sub

End Class
0
 
marklorenzCommented:
Not sure what you're asking - do you mean an "empty" spot when rendered?
0
 
Micki-WeaverAuthor Commented:
.Net, C# if you would but VB is ok

a hole in a form
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Bob LearnedCommented:
If you set the TransparencyKey, and have a region that is a that color, there will be a hole bored through the form.

Bob
0
 
Micki-WeaverAuthor Commented:
I can't allways count on having control of the TransparencyKey, or form backcolor, any other ways??
0
 
Micki-WeaverAuthor Commented:
a upgrade and in C#

        public static void MakeHole(System.Windows.Forms.Form FormIN, System.Drawing.Rectangle RectangleIN)
        {
            System.Drawing.Size SizeIN = FormIN.Size;
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            // start with a rectangle that represents the whole form
            gp.AddRectangle(new Rectangle(0, 0, SizeIN.Width, SizeIN.Height));

            // add an ellipse...which is removed from the rectangle above
            int w = FormIN.Width / 4;
            int h = FormIN.Height / 4;
            gp.AddEllipse(RectangleIN);

            // create a Region from the GraphicsPath and set it...
            FormIN.Region = new Region(gp);
        }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.