简体   繁体   English

Windows.Form不会显示

[英]Windows.Form won't show

All I want to do is display a blank windows form. 我想要做的就是显示一个空白的窗体。 I am using Visual Studio and was following this tutorial https://msdn.microsoft.com/en-us/library/windows/desktop/bb153258(v=vs.85).aspx However, when I ran it, nothing happened. 我正在使用Visual Studio并且正在学习本教程https://msdn.microsoft.com/en-us/library/windows/desktop/bb153258(v=vs.85).aspx但是,当我运行它时,什么也没发生。 A blank window did not open. 一个空白的窗口没有打开。 I simplified the code to see what the problem was, so here is my code: 我简化了代码以查看问题所在,所以这是我的代码:

public partial class CreateDevice : Form
{
    static void Main()
    {
        CreateDevice frm = new CreateDevice();
        frm.Show();
    }
    public CreateDevice()
    {
        this.ClientSize = new System.Drawing.Size(400, 300);
        this.Text = "D3D Tutorial 01: CreateDevice";
    }
}

Except when run, nothing happens. 除了跑步,没有任何反应。 I appreciate any advice. 我很感激任何建议。

Edited There were actually several things wrong with your code. 编辑你的代码实际上有几个问题。 First, you need a Program class with a static Main method--this is where the computer enters your program and starts running things, without it the computer won't do a thing. 首先,你需要一个带有静态Main方法的Program类 - 这是计算机进入程序并开始运行的地方,没有它,计算机就不会做任何事情。 You need a partial class--not merely a method--inheriting from Form . 你需要一个部分类 - 不仅仅是一个方法 - 继承自Form And finally, inside the Program.Main method you need Application.Run which runs an application context (if you give it a Form type argument it creates the context automatically). 最后,在Program.Main方法中,您需要运行应用程序上下文的Application.Run (如果您给它一个Form类型参数,它会自动创建上下文)。 You need to call Application.Run instead of show : 您需要调用Application.Run而不是show

static class Program
{

    static void Main()
    {
        CreateDevice frm = new CreateDevice();
        Application.Run(frm);
    }

}
public partial class CreateDevice : Form
{
    public CreateDevice()
    {
        this.ClientSize = new System.Drawing.Size(400, 300);
        this.Text = "D3D Tutorial 01: CreateDevice";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM