Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends


I have Problem in Dividing A rectangle into no of pieces With Given Values

Eg

I am able Draw A rectangle With Coordinates 600*600

Now i want divide the same rectangle with 200*200 and 100*100 and so on

plz any code help me

i am working in c# windows application


Thank u For replay

sorry i will make u clear


the 1st rectangle is having coordinates 600*600

now i want draw 2nd rectangle with coordinates 200*200 inside the 1st rectangle,

now i want to draw 3rd rectangle with coordinates 100*100 inside the 1st rectangle itself

but 2nd and 3rd rectangle should not overlap

like this i will draw as many as i want
Posted
Updated 16-Aug-13 1:03am
v3

questions seems unclear, are you looking to make the rectangle smaller? or make a bunch of tiny rectangles within the rectangle?

if its just making the rectangle smaller that's an extremely beginner task,
RectangleName.Width /= 200*200;
RectangleName.Height /= 200*200;

of if you wanted to change the position of X and Y by dividing each by 200 it would be
RectangleName.X /= 200;
RectangleName.Y /= 200;

But it can't be that, so what is your real question explained better?
 
Share this answer
 
v3
Comments
kiran murkal 16-Aug-13 7:04am    
Thank u For replay

sorry i will make u clear


the 1st rectangle is having coordinates 600*600

now i want draw 2nd rectangle with coordinates 200*200 inside the 1st rectangle,

now i want to draw 3rd rectangle with coordinates 100*100 inside the 1st rectangle itself

but 2nd and 3rd rectangle should not overlap

like this i will draw as many as i want
//So start with having a list of rectangles
//this is to keep track of all the rectangles you're creating within your method)
List<Rectangle> RectList = new List<Rectangle>();
public void CreateRectangles(int numberofrects)
{
    // when calling this method, you put in how many rectangles you want (INCLUDING) the first one of 600, 600
    Rectangle OldRectangle = new Rectangle(600, 600, 100, 100);
    for (int i = 0; i < numberofrects; i++)
    {
        Rectangle NewRectangle = new Rectangle(OldRectangle.X + (100), OldRectangle.Y + (100), OldRectangle.Width -= (100), OldRectangle.Height -= (100));
        RectList.Add(NewRectangle);
        OldRectangle = NewRectangle;
    }
}


Now to use these rectangles to draw, you're going to have to use the list.

ie: for (int i = 0; i < RectList.count; i++)
{
//your code for drawing the specific rectangle
//( Draw(blahblah,<yourrectangle is="">RectList[i]
}

Sorry if it looks messy, i tried to make it as clear as possible to a new c#er

edit: haha i realize this still isnt' what you want. Maybe upload a picture to imgur.com and paste it here
 
Share this answer
 
v5

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