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 254279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:50:00+00:00 2026-05-11T21:50:00+00:00

I have two controls which are both contained within a user control. Panel location:

  • 0

I have two controls which are both contained within a user control.

  • Panel location: 49, 400
  • Panel size: 787, 70
  • Picturebox location: 25, 0
  • Picturebox Size: 737, 700

Picturebox is seen underneath panel.

I could use some advice on the best way to determine the area of the PictureBox image covered by the panel, so I can copy the image onto the panel correctly in DrawImage call.

My answer is: I will copy screen from this area: 24,400 top left, it will be 714 wide, 70 high
But how do I automate to work with any combination of panel and picture box for a re-usable control?

Background if you need more info: The PictureBox contains an image of a map. The panel contains tools for manipulating the map, panel is positioned on top of PictureBox. Panel needs to be semi-transparent so the map image is still seen through it.

Because of the way that winforms paints transparency, (calling up through the control tree to have the parent paint its self) – when I paint my panel it takes on the color of the background of the usercontrol, not the image of the map below it.

My thoughts for this are: if I can copy the image of the map that is below the panel to the background of the panel and then paint my semi-transparent background I will be able to simulate the effect that designers have requested.

Original code from the panel is where I grab the image from the picture box.

            Dim x As Integer = GetXOffset()
            Dim y As Integer = GetYOffset()

            Dim sizeOfImage As Size = New Size(ClientRectangle.Width _
                                  , ClientRectangle.Height)
            bmpScreenshot = New Bitmap(sizeOfImage.Width, sizeOfImage.Height, _
                     PixelFormat.Format32bppArgb)

            gfxScreenshot = Graphics.FromImage(bmpScreenshot)
            Dim destrect As New Rectangle(ClientRectangle.X, ClientRectangle.Y, _
                        ClientRectangle.Width, ClientRectangle.Height)


            gfxScreenshot.DrawImage(mPictureBox1.Image, destrect, New Rectangle(x, y, _
               sizeOfImage.Width, sizeOfImage.Height), GraphicsUnit.Pixel)

I copy this image to the background in the OnPaint event.

If bmpScreenshot Is Nothing Then
            PushScreen()
        End If
        If Not bmpScreenshot Is Nothing Then
            pevent.Graphics.DrawImage(bmpScreenshot, GetPaintOffset())
        End If

And finally, after adding the change from the accepted answer, here is the modified code where the image is grabbed.

 Dim sizeOfImage As Size = New Size(ClientRectangle.Width _
                                  , ClientRectangle.Height)
            bmpScreenshot = New Bitmap(sizeOfImage.Width, sizeOfImage.Height, PixelFormat.Format32bppArgb)

            gfxScreenshot = Graphics.FromImage(bmpScreenshot)

            Dim rect As Rectangle = Rectangle.Intersect(mPictureBox1.Bounds, Bounds)
            Dim destrect As Rectangle = New Rectangle(rect.Left - Left, _
             rect.Top - Top, rect.Width, rect.Height)
            Dim imgrect As Rectangle = _
              New Rectangle(rect.Left - mPictureBox1.Bounds.Left, _
              rect.Top - mPictureBox1.Bounds.Top, rect.Width, rect.Height)

            gfxScreenshot.DrawImage(mPictureBox1.Image, destrect, _
               imgrect, GraphicsUnit.Pixel)
  • 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-05-11T21:50:00+00:00Added an answer on May 11, 2026 at 9:50 pm

    You can use the Rectangle.Intersect method (together with a tiny bit of calculation) to get the result you want. C# sample:

    Rectangle rect = Rectangle.Intersect(_pictureBox.Bounds, _panel.Bounds);
    rect = new Rectangle(rect.Top - _panel.Top, rect.Left - _panel.Left, rect.Width, rect.Height);
    e.Graphics.FillRectangle(Brushes.Red, rect);
    

    Update

    I played around with this a bit more and came up with the following solution, that I find a bit simpler and also a bit more robust (this time VB.NET code):

    Private Sub DrawPanelBackground(ByVal pictureBox As PictureBox, ByVal panel As Panel)
        If pictureBox.Image Is Nothing Then
            Exit Sub
        End If
    
        Dim rect As Rectangle = New Rectangle(pictureBox.Left - panel.Left, pictureBox.Top - panel.Top, pictureBox.Image.Width, pictureBox.Image.Height)
        Using g As Graphics = Panel.CreateGraphics()
            g.DrawImage(pictureBox.Image, rect)
        End Using
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 160k
  • Answers 160k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you are quite on the right way. One… May 12, 2026 at 11:43 am
  • Editorial Team
    Editorial Team added an answer Found out how to do it: module MyWorld def MyWorld.extended(obj)… May 12, 2026 at 11:43 am
  • Editorial Team
    Editorial Team added an answer There is no built-in facility in Windows Mobile for doing… May 12, 2026 at 11:43 am

Related Questions

How to create a WPF application that can be deployed as either a XBAP
I have a c# .net winforms solution and I want to create two different
We code in C# using VS2008 SP1. We have a server that runs Team
I have written a custom Silverlight control based on Control. I have two DependencyProperties

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.