hi
i want only that part of a picture which is visible in picturebox
the picture may be larger than the picturebox but i want to copy only the visible part

anybody help

thank u vey much

Dani AI

Generated

Quick note that builds on the thread: a one-line assignment can seem to work in simple cases, but it does not always produce an independent bitmap that exactly matches what the user sees (scaling, centering, or container scrolling change the visible pixels). Below are two reliable approaches that capture exactly the visible area so the result is predictable across SizeMode/settings.

For VB.NET: render the control into a bitmap and store a copy so it is independent of the original Image. This captures exactly what the control draws (including any clipping or scaling).

Dim bmp As New Bitmap(pictureBox1.Width, pictureBox1.Height)
pictureBox1.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
pictureBox2.Image = New Bitmap(bmp)

For classic VB (VB6): use the PictureBox.PaintPicture overload that accepts source coordinates. Paint only the source rectangle that corresponds to the visible portion into a destination PictureBox or StdPicture.

' PaintPicture syntax: dest.PaintPicture sourcePicture, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH
Picture2.Cls
Picture2.PaintPicture Picture1.Picture, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, srcX, srcY, srcW, srcH

Notes and cautions: account for PictureBox SizeMode/Stretch/Zoom — if the image is scaled you must compute source coordinates using the scale factor. Assigning one control's Image to another often shares the same object; clone or create a new Bitmap if you need an independent copy. Thanks to and for the original discussion that led to these more robust options.

got it

share your answer friend, so other member can learn from you :)

im sorry forgot

here is the code

Picture2.Picture = Picture1.Image

thats enough and u wil get the visible part of picturebox1 in picturebox2

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.