You can calculate your points as follow:
Color[] points = new Color[8];
int[] xPos = { -1, 0, 1, -1, 0, 1, -1, 1 };
int[] yPos = { -1, -1, -1, 1, 1, 1, 0, 0 };
for (int i = 0; i < 8; i++)
points[i] = ((Bitmap)pictureBoxSourcePicture.Image).GetPixel(clickedX + xPos[i], clickedY + yPos[i]);
And then calculate the sumRed, sumGreen and SumBlue:
for (int i = 0; i < points.Length; i++)
{
SumRed += Math.Pow( (Math.Abs(oPoint.R - points[i].R)),2);
SumGreen += Math.Pow((Math.Abs(oPoint.R - points[i].G)), 2);
SumBlue += Math.Pow((Math.Abs(oPoint.R - points[i].B)), 2);
}
It's more short and easy to understand. Hope this will be useful