XNA and WinForms
Friday, January 23rd, 2009A lot of people don’t think it is possible to have winforms items (like buttons and dropdowns) in an XNA application, but I am here to prove them wrong. There is a ridiculously simple method of adding controls to your XNA application INSIDE the XNA window without too much hassle – as long as you are ok with coding up the items by hand.
One downfall is that this won’t work on the Xbox 360 since System.Windows.Forms is not included in the things XNA can render, but these types of UIs aren’t really the kind that would work well on an Xbox anyway.
Here is my method of adding the controls and a screenshot of the app running:
protected override void Initialize() { var list = new ListBox(); list.Items.Add("Here"); list.Items.Add("Are"); list.Items.Add("Some"); list.Items.Add("Items"); Control.FromHandle(Window.Handle).Controls.Add(list); }
I hope this method solves a lot of the issues people seem to be having with using these Controls together with XNA.