Click here to Skip to main content
13,249,813 members (80,923 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a picturebox (origBox) within a panel with auto scroll set on.
A number of lines are drawn on the origBox. Later on a graphics path is drawn on the origBox. Now I am trying to crop and magnify a part of the origBox picturebox contents (bitmap) to another picturebox (cropBox). The cropping and magnification work, but there is a problem:
I use a rectangle to select a part of the origBox. The rectangle covers image of the lines drawn directly on the origBox and part of the graphics path drawn on the origBox. However, on the cropBox, only the selected lines are displayed; the part of graphics path that was selected is missing.

Could anyone, please, explain why this happens? Is graphics path a transparent layer that is not picked by copying a part of a picturebox (eg. origBox) bitmap?

Posted 9-Jan-13 12:09pm
Wrong way, go back! I explained it all in my answer, please see.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all, you try to abuse PictureBox, as too many do. This control is totally useless, unless you want to do something very simple, in a very simplified way. In all other cases, it presents just hassled giving nothing in return. I'll tell you what to do instead.

Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

See also:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my application?[^].

And magnification is done by System.Drawing.Graphics.Transform:[^].

As to cropping, it's not needed at all (if you are not using PictureBox which will only screw up it :-)). For rendering (see above), use some control of required size, all rendering will be cropped by its bounds. As simple as that.

captab1 9-Jan-13 21:24pm
Let me clarify, my original statement of the problem. When I say I draw on picturebox origBox, I actually create a bitmap, a graphics canvas for the bitmap, and then draw on the canvas. Once this is done, I use the origBox to display what was drawn by assigning the bitmap to the picturebox origBox.

The drawing is displayed fine, but trying to copy part of it (crop) to cropBox bitmap suffers from the above described problem.
OK, it clearly justifies that you should not use PictureBox, all my recommendations are valid. Please see.
You just went in wrong directions, but it's not too late to fix it. Besides, you will save a lot of time, because doing all your manipulations are highly excessive...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100