Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I created a polygon by clicking points in the picture box.

So the points are user defined at the run time.

I want to make an offset polygon over it.

How to make polygon offset at all sides.

Can anyone give me the code





Please help me to create an offset polygon
Posted
Updated 27-Feb-14 22:22pm
v4
Comments
OriginalGriff 27-Feb-14 2:56am    
And how did you store the polygon?
How are you using it?
Show us the code, and we might be able to help...
Use the "Improve question" widget to edit your question and provide better information.
KUMAR619 27-Feb-14 4:21am    
@OriginalGriff

I have added my code please help me get an offset polygon
Sergey Alexandrovich Kryukov 27-Feb-14 2:58am    
Forget about using totally redundant PictureBox for anything dynamic/interactive/animated, this is totally wasteful. Don't do thing so much more complex than they have to be.
—SA
BillWoodruff 27-Feb-14 3:44am    
Is there something new here that was not asked in the first question ?
http://www.codeproject.com/Answers/722646/How-to-create-Offset-Polygon-using-Csharp

Have you tried using 'Translate on the Region of your Polygon ? See:
http://msdn.microsoft.com/en-us/library/389ys2bx(v=vs.100).aspx

It would help to know what you want to DO with the polygon once it is created, and offset: are you going to fill it with a Color, "stroke" its outline, or fill it with the contents of the graphic in the PictureBox, ... or ?
KUMAR619 27-Feb-14 6:40am    
@BillWoodruff

I was asked to offset a polygon and shade the area between two polygons i.e outer-inner area

1 solution

Assuming that the part you are having difficulty with is this:
C#
case MouseButtons.Middle:
                    Point[] offsetPoint=polygonPoints.ToArray();

                    int resizeValue = 10;
offsetPoint.Select(x => new Point(x.X*resizeValue, x.Y*resizeValue));
graphics.DrawPolygon(new Pen(Color.Green), offsetPoint);
                        polygonPoints.Clear();

                    break;

Then it does offset a point - but you then throw it way...
The Select method creates a new Enumerable, which is what you want, but...it doesn't replace the old one.
Probably, what you want to do is:
C#
case MouseButtons.Middle:
                    Point[] offsetPoint=polygonPoints.ToArray();

                    int resizeValue = 10;
                    offsetPoint = offsetPoint.Select(x => new Point(x.X*resizeValue, x.Y*resizeValue)).ToArray();
                    graphics.DrawPolygon(new Pen(Color.Green), offsetPoint);
                    polygonPoints.Clear();

                    break;
Which stores the newly offset Points so you can use them.
 
Share this answer
 
Comments
KUMAR619 27-Feb-14 5:07am    
@OriginalGriff
Thanks for replying but that's not my task.
I was asked to offset a polygon.

From the above code if I click with mOuse left button any where points gets added to the list
and when I press right mouse button a polygon appears by joining the points.

Now my task is to offset or overlap that polygon.

Two polygons should be visible one offsetting the other
Can you get me the code
OriginalGriff 27-Feb-14 5:36am    
Sorry? Where does the second polygon come from? Or possibly the first?


Remember that we can't see your screen, access your HDD, or read your mind, so we only get to work with what you tell us!
KUMAR619 27-Feb-14 5:41am    
@OriginalGriff
Its not necessary to create a second polygon.
The first polygon may offset with increased size in all direction
OriginalGriff 27-Feb-14 6:03am    
So what is the problem?
Try to explain from the beginning - because you are just repeating yourself, and if I don't understand what you need, I can't make suggestions!
KUMAR619 27-Feb-14 6:10am    
@OriginalGriff

I was asked to make an offset polygon
That is polygon having centrepoint common but increased sides
Can you get me the code for offset polygon

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