Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 0 down vote accepted

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)

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
share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.