Graphics.FillRectangle problem

Posts 1–3 of 3 · Page 1 of 1
Graphics.FillRectangle problem
Hello everyone!

The following source-code is working but not in the way i want and I can't figure it out why.

This is my code:

Declaration
Code:
Dim sfondoImg As Bitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
Dim G As Graphics = Graphics.FromImage(sfondoImg)
Usage
Code:
G.FillRectangle(Calc_arrayB(i), x * (k + 1), y * (k + 1), k, k)
This is what I get




Why there are those white spaces between every rectangle?
They must be automatic because the coords x-y of each rectangle are correct, no offsets added.


Any ideas? Thanks.
Quote Originally Posted by Sixx93 View Post
.
Nope, the spaces aren't added automatically.
G.FillRectangle(Calc_arrayB(i), x * (k + 1), y * (k + 1), k, k)
is wrong.

First 2 loops would result in:
round 1:
x = 0, y = 0, k = 10 (assume 10 for 'box size' -- 'k' doesn't change inside function, so doesn't really matter?)

0 * (k+1), 0 * (k+1)

x=0, y=0 == first grid location (starting at top-left). ok.

round 2:
x = 1, y = 0, k = 10

1 * (k+1), 0*(k+1) //Scanning left-right, then top-down.

1* (11)

x = 11. not ok.

our first box's x position was at 0, our next one is at 11..if each box is '10 in size' it should be 0 to 9, with the next one starting at 10; but it starts at 11 - the equation is wrong.

edit: looks like simply x * k would work to calculate the x pos. of each 'box'.

G.FillRectangle(Calc_arrayB(i), x * k, ****, k, k)

x=0,y=0,k=10;

0 * k = 0

next loop
1 * k = 10 //ok
next loop:
2 * k = 20

box 1 goes from 0 to 9, box 2 goes from 10 to 19, bot 3 goes from 20 to 29. Seems to follow the pattern.
I'm sure the yPosition is a similar story.
Quote Originally Posted by abuckau907 View Post
Nope, the spaces aren't added automatically.


is wrong.

First 2 loops would result in:
round 1:
x = 0, y = 0, k = 10 (assume 10 for 'box size' -- 'k' doesn't change inside function, so doesn't really matter?)

0 * (k+1), 0 * (k+1)

x=0, y=0 == first grid location (starting at top-left). ok.

round 2:
x = 1, y = 0, k = 10

1 * (k+1), 0*(k+1) //Scanning left-right, then top-down.

1* (11)

x = 11. not ok.

our first box's x position was at 0, our next one is at 11..if each box is '10 in size' it should be 0 to 9, with the next one starting at 10; but it starts at 11 - the equation is wrong.

edit: looks like simply x * k would work to calculate the x pos. of each 'box'.

G.FillRectangle(Calc_arrayB(i), x * k, ****, k, k)

x=0,y=0,k=10;

0 * k = 0

next loop
1 * k = 10 //ok
next loop:
2 * k = 20

box 1 goes from 0 to 9, box 2 goes from 10 to 19, bot 3 goes from 20 to 29. Seems to follow the pattern.
I'm sure the yPosition is a similar story.
Thanks for the answer, I'm testing it right now. I'll post back the result.

Edit:
Yes, you're right. It works.



I thought it was right to use x/y * (k+1). I had the idea while I was at school then, when I arrived at home I wrote the code without ask my self if it was right xD

/req close
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us