Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:07:01+00:00 2026-06-10T06:07:01+00:00

I have a System.Drawing.Region object with the GetBounds() method returning {X = 0.0 Y

  • 0

I have a System.Drawing.Region object with the GetBounds() method returning

{X = 0.0 Y = 0.0 Width = 120.0 Height = 120.0}

However when I execute the Exclude() method with a rectangle:

region.Exclude(New System.Drawing.Rectangle(60, -20, 100, 160))

I would expect the Region.GetBounds method to return

{X = 0.0 Y = 0.0 Width = 60.0 Height = 120.0}

instead the Exclude() call appears to do nothing at all. Similarly with the Intersect() method

region.Intersect(New System.Drawing.Rectangle(60, -20, 100, 160))

I would expect to see

{X = 60.0 Y = 0.0 Width = 60.0 Height = 120.0}

but again there is no change. Is this correct?

Edit: Specific context

I am working with the OnPaintBackground() method on a larger project in the direction of a base Control with general transparency: What is a general solution to creating a transparent control?

Protected Overrides Sub OnPaintBackground(pevent As System.Windows.Forms.PaintEventArgs)
    Dim initialClip As Region = pevent.Graphics.Clip

    'Develop list of underlying controls'
    Dim submarinedControls As New List(Of Control)
    For Each control As Control In Parent.Controls.ToArray.Reverse
        If control IsNot Me AndAlso control.Visible AndAlso Me.ClientRectangle.IntersectsWith(control.RelativeClientRectangle(Me)) Then : submarinedControls.Add(control)
        Else : Exit For
        End If
    Next

    'Prepare clip for parent draw'
    pevent.Graphics.Clip = New Region(initialClip.GetRegionData)
    For Each control As Control In submarinedControls
        pevent.Graphics.Clip.Exclude(control.RelativeClientRectangle(Me))
    Next

    ...
End Sub

At the ‘Prepare clip for parent redraw’ section, after the initial clip has been recreated, its bounds are as specified. The next step is to exclude any underlying controls and only paint the areas where this control interacts directly with the background of the parent control. The exclude method here I can see is receiving the larger rectangle as its argument (as a Watch), but after the Exclude occurs, nothing about the clip’s bounds changes.

Edit: Possible Resolution

It appears the Graphics.Clip region is managed by the Graphics object and is immutable. Replacing the exclusion snippet with the following yields all expected results:

    'Prepare clip for parent draw'
    Dim parentClip As System.Drawing.Region = New System.Drawing.Region(initialClip.GetRegionData)
    For Each Control As Control In submarinedControls
        parentClip.Exclude(Control.RelativeClientRectangle(Me))
    Next
    pevent.Graphics.Clip = parentClip

RelativeClientRectangle():

<Runtime.CompilerServices.Extension()>
Public Function RelativeClientRectangle(control As System.Windows.Forms.Control, toControl As System.Windows.Forms.Control) As System.Drawing.Rectangle
    Return New System.Drawing.Rectangle(control.RelationTo(toControl), control.Size)
End Function

RelativeTo():

<Runtime.CompilerServices.Extension()>
Public Function RelationTo(control As System.Windows.Forms.Control, toControl As System.Windows.Forms.Control) As System.Drawing.Point
    Return control.PointToScreen(New Point(0, 0)) - toControl.PointToScreen(New Point(0, 0))
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:07:02+00:00Added an answer on June 10, 2026 at 6:07 am

    While I cannot be certain, all work seems to agree with my final edit that Graphics.Clip is managed more strictly than an orphan region. The observed behaviour is completely resolved when preparing a region offline for modification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code : System.Drawing.Rectangle desktop_Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds which gives me the
If I have two System.Drawing.Rectangle objects on a canvas and a Point , what
i have a web-service that will be returning a collection of System.Drawing.Image objects. My
I have a System.Drawing.Pen _pen . When in some iterations is setting _pen.Width =
I have an object of type System.Drawing.Image and would like to display this image
I have a method to copy the data out of a System.Drawing.Bitmap which looks
So far I have this code. $form = New-Object System.Windows.Forms.Form $form.Size = New-Object System.Drawing.Size(900,600)
I have a drawing application developed in winforms C# which uses many System.Drawing.Bitmap object
I have an object of the type System.Drawing.Image and want to make every pixel
I have the following method which works fine: button21.FlatAppearance.BorderSize = 0; button21.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.