Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

XNA WinForms Reduex!

Published 6/15/2009 by createdbyx in News | Programming | XNA

First start a new xna window game project. Then add a new "MDI Parent Form" to the project. After that change the code in the Program.cs file to look like this ...

static void Main(string[] args)
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    using (Game1 game = new Game1())
    {
        MDIParent1 mainMDIForm = new MDIParent1();
        var gameWindow = Control.FromHandle(game.Window.Handle) as Form;
        if (gameWindow != null)
        {
            gameWindow.MdiParent = mainMDIForm;
        }

        mainMDIForm.Show();
        gameWindow.Show();
        game.Run();
    }
}

Now press F5 to run the application. Voila! You can now proceed to add game editing or other win form controls to the MDI window for what ever you need. But some initial testing raised a few minor issues.

The first one is that once in a while the viewport does not get updated if the game window is resized. There is also a issue where keyboard keys don't work properly if the game window is the active window. To over come this just make sure that after you are finished interacting with the game window to just deactivate the window again. Then you will be able to press Alt-F to bring up the file menu for example.


Comments (3) -

llullu | Reply

7/11/2009 1:57:28 PM #

Hi, thanl's for your site.
i'm beeginer on xna and c#, and on programation at all, and i searsh over the net informations about xna and winforms, the winforms series on xna creator it is really hard for start with, and other blog or exemples are also too complex because it is part of heavy class or rewrited engine over xna with multiples dependences  ...
thank's for your more simple exemples, my questions is:
-Do you plan to add more possibility about xna and winforms without MDI ?
-Have you find some turn around or solutions about the issues in the MDI forms exemple ?

sorry for my english Smile

Created by: X | Reply

7/13/2009 12:38:04 AM #

I have made a new blog post that uses a custom written control that can be used to render xna graphics. www.createdbyx.com/.../...-So-much-work-to-do.aspx

I probably will not be doing much more with MDI and xna. The whole reason I made the example was that I was looking into different ways I could create a level editor and other tools. Based on my current work and the way I have my plug ins written for my game engine I chose to go with a SDI modal.

llullu | Reply

7/13/2009 9:38:25 PM #

Hi, thank's to reply, i will take a look to your new post.

Add comment



biuquote
  • Comment
  • Preview
Loading






Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume