Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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'm playing around with random map generation and what I want to do is:

  1. Input a command to generate a random map.
  2. A texture will be created resembling the generation, each pixel resembling each tile.
  3. A new window will pop-up, without removing the original one, that will contain the texture.

I know how to do this except for the last part. Would someone please tell me how to create a new window and draw a texture to this window?

share|improve this question
up vote 4 down vote accepted

Unfortunately there isn't anything in the XNA framework which could help you, but there are two other solutions:

The second solution is simpler because you can use it in this way:

System.Windows.Forms.Form form = new System.Windows.Forms.Form();

Then if you want to show the texture in the new form you should create a bitmap, and you can do it in this way (you have to add a reference to System.Drawing and System.IO):

System.IO.MemoryStream ms = new System.IO.MemoryStream();
Texture2D texture = Content.Load<Texture2D>( "Images\\test" ); //example
texture.SaveAsJpeg( ms, texture.Width, texture.Height );
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( ms );

The complete code could be:

protected override void Update(GameTime gameTime){


private Bitmap CreateBitmap(Texture2D texture){
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    texture.SaveAsJpeg( ms, texture.Width, texture.Height );
    return new System.Drawing.Bitmap( ms );

private void ShowForm(Bitmap bmp){
    System.Windows.Forms.Form form = new System.Windows.Forms.Form();
    form.Location = new System.Drawing.Point(100, 100); //example
    form.Text = "Texture2D";
    form.BackgroundImage = bmp; //Set the texture as background 
    form.ClientSize = bmp.Size;
share|improve this answer
Thanks man, I just added this and it works perfectly, brilliant answer! – John Oct 3 '12 at 21:05

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.