2
\$\begingroup\$

I am writing a turn based strategy game in C#. My GUI implementation consists of class that extends Form containing a class that extends Panel. When I render the GUI I draw to the paint method in the panel.

I am trying to figure out what is the best way for handling form re-size events. I know I want a minimum window size, but I would prefer to not have a maximum or a set size.

Ideally the GUI would reveal more/less of the map as the user changes the window size. I would like to avoid scaling the graphics if at all possible.

What is the best way to handle re-size events?

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

The best way I know of would be to redraw your screen on resize and determine the number of map tiles to draw based on the current width and height of your form. Just make sure you anchor your display panel to all sides of the form (which forces it to scale with the form)

private void MapForm_Resize(object sender, EventArgs args)
{
    Draw();
}

private void Draw()
{
    // you said you used a panel to display stuff
    // The +1 is incase you have a partial tile that needs to be displayed, 
    // this is really only needed if you glide the camera rather than snapping.
    int tilesInXDirection = 1 + displayPanel.width  / tileWidth;
    int tilesInYDirection = 1 + displayPanel.height / tileHeight;

    for (int x; x < tilesInXDirection ; x++)
    {
        for (int y; y < tilesInYDirection ; y++)
        {
            // Draw your tiles based on current location
        }
    }
}
\$\endgroup\$
0
\$\begingroup\$

Well in C#, use the built in events system and then when the panel is resized simply loop through all of the controls and adjust based on parameters that you want

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .