Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
3.00/5 (1 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?

Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 9-Jan-13 17:19pm    
Wrong way, go back! I explained it all in my answer, please see.
—SA

1 solution

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 vb.net application?[^].

And magnification is done by System.Drawing.Graphics.Transform: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.transform.aspx[^].

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.

—SA
 
Share this answer
 
Comments
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.
Sergey Alexandrovich Kryukov 9-Jan-13 22:17pm    
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...
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900