Digital Autumn

I'm new to C# and Windows coding, and I'm working through some books, but I wanted to jump ahead a bit and do something interesting, have a SplitContainer panel do something using the XNA graphics engine, even just clearing to cornflower blue or something like that.

I looked around to see how to do something like this, and found a few partial examples, so I tried to piece together something that would work.

I tried, and I keep getting a DeviceNotSupportedException when I tried to create a new graphicsDevice.

I can do the XNA tutorials, so I have to believe my graphics adapter is capable of this, but I'm doing something wrong.

Thanks in advance.

Here is what I have:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
private GraphicsDevice graphicsDevice;

public Form1()
{
InitializeComponent();

PresentationParameters pp = new PresentationParameters();
pp.IsFullScreen = false;

graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter,
DeviceType.Reference, splitContainer1.Panel2.Handle,
CreateOptions.SoftwareVertexProcessing, pp);
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}




Re: XNA Framework Help please: GraphicsDevice in a form

CodePfo

Try putting a regular panel or label in the split pane and attaching your device to that. Be warned that every time it resizes you will lose the device.




Re: XNA Framework Help please: GraphicsDevice in a form

Digital Autumn

Either I didn't understand, or it didn't work.

I replaced the "splitContainer1.Panel2.Handle"

with pnlPanel.Handle, then lblLabel.Handle and neither helped. (I created the panel and the label first in the form, of course.)




Re: XNA Framework Help please: GraphicsDevice in a form

Fluxtah

This works on my crappy <insert 4 letter company name here> laptop which I think has an ATI Mobility Radeon 9000, I stripped it down to just what you need and I use a picture box (instance name of RenderBox) for rendering rather than a panel, I did not need it to rapidly update so I used the Timer class so if you want faster drawing then you will have to find other means, oh , and it was also written with beta1.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Test
{
  public partial class Form1 : Form
  {
    GraphicsDevice _Device;
    public Form1()
    {
      InitializeComponent();
    }

    protected override void OnLoad(EventArgs e)
    {
      base.OnLoad(e);

      PresentationParameters presentParams = new PresentationParameters();
      presentParams.BackBufferWidth = 800;
      presentParams.BackBufferHeight = 600;
      _Device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, 
                                DeviceType.Hardware, RenderBox.Handle, 
                                CreateOptions.HardwareVertexProcessing, 
                                presentParams);

      _Timer = new Timer();
      _Timer.Interval = 1;
      _Timer.Tick += new EventHandler(Draw);
      _Timer.Start();
    }

    void Draw(object sender, EventArgs e)
    {
      _Device.Clear(Color.CornflowerBlue);

      _Device.BeginScene();

      // TODO: Add drawing code here


      _Device.EndScene();

      _Device.Present();
    }
  }
}




Re: XNA Framework Help please: GraphicsDevice in a form

Digital Autumn

I took out the begin and end scene lines, and it worked!

Thanks!






Re: XNA Framework Help please: GraphicsDevice in a form

Michael Hansen

take look at this tread

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1059538&SiteID=1

you can download a sample

it do not use the game.dll to use the content manager