I have the PictureBox Cursor.Clip = pboxSetup.RectangleToScreen Blues

Thanks for looking,,,

I have been trying to get the rectangle of a centered image of a picturebox,



image resized from whatever to 800x600 or 600x800 what ever the image is portrait or landscape,,,

picturebox is set to center image,,,, image is centered in the picturebox,,, how do i get the rectangle of the centered image...

I need help boy wonder, because i have the PictureBox Cursor.Clip = pboxSetup.RectangleToScreen math phart Blues (la la la)

I will check back in kids on this same bat channel, same bat time tomorrow

Wholly rectangle Batman!


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Since I don't think you could possibly find out about thta, I would suggest a different approach: Paint the picture yourself. If you need any code to do so, check out this thread:
This way you'll have complete control over what's in and what size it is.

Cheers & HTH,
Bob LearnedCommented:
How is the image "centered" on a PictureBox?

Sorry Ray,
 But for what you are doing with picking rgb on screen I do not see a need to center an image. When you can just use whatever area it fills or change the pic box to fill to pic box..
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

5thcavAuthor Commented:
i need this approach, I’m centering the image by the Pbox default centering,,

I’m resizing the image to fit the pbox height/width so i should be able to tell where the image is centered?\

I almost get it but my x,y positioning is week, toss in the percentage of the image resizing and its relational distance form the PBox’s boarders, I start getting brain pain


    Private Sub lbImageSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbImageSize.SelectedIndexChanged

        Select Case sender.SelectedIndex
            Case 0
                ImageSize = 1
            Case 1
                ImageSize = 0.9
            Case 2
                ImageSize = 0.8
            Case 3
                ImageSize = 0.7
            Case 4
                ImageSize = 0.6
            Case 5
                ImageSize = 0.5
            Case 6
                ImageSize = 0.4
            Case 7
        End Select

        If CorrectFirstTimelbImageSizeSetSelected = True Then

Public Shared Function getThumbnailImage(ByVal strFile As String, ByVal intWidth As Integer, ByVal IntHeight As Integer) As Image

            If File.Exists(strFile) Then
                Dim bmp As New Bitmap(strFile)
                If bmp.Width > bmp.Height Then
                    img = New Bitmap(bmp, intWidth, CType(intWidth * bmp.Height / bmp.Width, Integer))
                ElseIf bmp.Width < bmp.Height Then
                    img = New Bitmap(bmp, CType(IntHeight * bmp.Width / bmp.Height, Integer), IntHeight)
                    img = New Bitmap(bmp, intWidth, CType(IntHeight * bmp.Height / bmp.Width, Integer))
                End If

                Return img
                Throw New FileNotFoundException
            End If

        Catch ex As Exception
           Return Nothing

        End Try
    End Function
5thcavAuthor Commented:
if i set the image size to 0.8 shouldnt the image be 0.2 into the center on all 4 sides?  i havent tryed yet, just had a brain storm,,,
5thcavAuthor Commented:
If i take a while to respond,,, im on the road 7am to 10pm and try to put in a little VB for and hour at night,,, :(
5thcavAuthor Commented:
planocz ,  rgb on screen  lol,, that was 10 days ago..

why do you think you really need the "picturebox with centered image" approach? If you are using the pb's .Image-property later on, then there still is ways of providing you with that by simply creating a little control that:
- inherits from panel
- includes double-buffering
- offers access to the image being drawn by means of properties (in/out)
- draws the image itself while centering it resp. taking the larger extension v/h and scaling the other one accordingly

In that control you could also keep track of the rectangle that the image is being centered to/in. I suppose that'll be a *lot* easier than always being one step behind the picturebox ...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
5thcavAuthor Commented:
My deal is ,
i would like to place small buttons on the image, the PB will range in size and must always maintain the correct aspect / ratio of the image (User Images). i find the resizing the image to scale and centering that image always results in a perfectly displayed image. when the user loads an image i need to recall the button location and correctly overlay them onto the image. when i get past this stage i will later add lines and arrows with descriptions.

Keep in mind the Pbox will resize and i plan to have a zoom control, I don’t want to alter the original image in any way.

Trust me, I have a need for this… (It may Solve world hunger and advance our knowledge of our universe!! (im so funny)) I appreciate everyone’s suggestions and concerns, im off this weekend so I’ll be spending that time resolving the issue.

I made the suggestion if I resize the image in code by 80% of the PB size and center that image into the PB, shouldn’t I just have to remove 20% from the PB edges?

Thanks Ray
5thcavAuthor Commented:
      Dim intPbLeftRght As Integer = (pboxSetup.Width - SetImageWidth) / 2
       Dim intPbTopBottom As Integer = (pboxSetup.Height - SetImageHeight) / 2
       sender.Parent = pboxSetup
       sender.Height = 5
       Cursor.Clip = pboxSetup.RectangleToScreen(New Rectangle(intPbTopBottom, intPbTopBottom, ImageWidth, ImageHeight))

Got it thanks 4 the help
5thcavAuthor Commented:
Cursor.Clip = pboxSetup.RectangleToScreen(New Rectangle(pboxSetup.Height - SetImageHeight) / 2, pboxSetup.Height - SetImageHeight) / 2, ImageWidth, ImageHeight))

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.