[C#] Bizarre problem - Point goes out of context immediately

Soldato
Joined
12 Apr 2004
Posts
11,788
Location
Somewhere
As title really. I'm declaring and initialising a Point struct, and as soon as it moves on to the next line, it's like it's just gone out of context completely, or at least that's what the debugger tells me. When I try to use it to create a Rectangle, it just defaults to (0, 0), rather than what the Point was supposed to be :confused:

Here's my code (offending line marked in red):
Code:
// Get image bounds
Point start = new Point(horizontalScroll.Value, verticalScroll.Value);
Size area = new Size(Math.Min(pictureBox.Width, m_Image.Width),
                     Math.Min(pictureBox.Height,m_Image.Height));
Rectangle visibleArea = new Rectangle(start, area);

// Draw image section
using (Graphics graphics = Graphics.FromImage(pictureBox.Image))
{
    // Draw background colour
    using (Brush backgroundBrush = new SolidBrush(m_BackgroundColor))
    {
        Rectangle pictureBoxArea = new Rectangle(new Point(0, 0),
                                                 new Size(pictureBox.Width, pictureBox.Height));
        graphics.FillRectangle(backgroundBrush, pictureBoxArea);
    }

    // Draw image to appropriate location
    int x = ((pictureBox.Width) / 2) - ((area.Width) / 2);
    int y = ((pictureBox.Height) / 2) - ((area.Height) / 2);
    [COLOR=Red]Point destinationStart = new Point(x, y);[/COLOR]
    Rectangle destination = new Rectangle(start, area);
    graphics.DrawImage(m_Image, destination, visibleArea, GraphicsUnit.Pixel);
}

Any ideas?

Probably just something really simple I've overlooked, as is usually the case :o
 
Last edited:
Back
Top Bottom