Directx window 调试时不会加载

Directx window will not load when debugged

我正在尝试创建 window 并将设备初始化到 window,但每次我 运行 程序 window 都不会加载。我在 visual studio 2015 年为 windows 表单应用程序执行此操作。 这里是 form1.cs:

using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
namespace DirectXTutorial2
{
public partial class Form1 : Form
{
    private Device device;

    public Form1()
    {
        InitializeComponent();
        InitializeDevice();
    }

    public void InitializeDevice()
    {
        PresentParameters presentParams = new PresentParameters();
        presentParams.Windowed = true;
        presentParams.SwapEffect = SwapEffect.Discard;
        device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
    }

    private void Render()
    {
        device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 0, 1);
        device.Present();
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        Render();
    }
}
}

有谁知道解决这个问题的方法吗? 我不知道它是否有帮助,但我正在 运行ning windows 10、64 位,Directx 2010,我之前已经添加了我的参考资料。

首先考虑在您的应用程序中使用 try catch,因为 DirectX 中发生了很多事情,因此您需要确认出错的步骤。

try
    {

        PresentParameters presentParams = new PresentParameters();
        presentParams.Windowed=true;
        presentParams.SwapEffect = SwapEffect.Discard;
        device = new Device(0, DeviceType.Hardware, this, 
                CreateFlags.SoftwareVertexProcessing, presentParams);

    }
    catch (DirectXException)
    { 
         return false; 
    }

尝试使用不同的设备类型,例如 DeviceType.Software

清除设备后添加开始和结束场景

device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
    device.BeginScene();
    device.EndScene();
    device.Present();

并尝试调用您的“Render; 'Main' 函数

中的函数

好的,我找到了解决问题的方法。开发人员不再支持托管代码的 DirectX。适用于 DirectX 的最新框架是 .net Framework 3.5。托管代码也不支持 64 位。要解决此问题,请转到项目属性。在应用程序选项卡中找到目标框架并将您的 .net 框架更改为 3.5 或更低。接下来转到构建选项卡并找到平台目标,将其更改为 x86。