注意:在 Visual Studio 中时,我并不是从制作一个 win 表单应用程序开始的,这是一个游戏的私人服务器,它是一个 .sln,其中包含 9 个项目,所有项目都可以一起编译和工作,我正在试验并看看是否可以它可以在其中执行Windows表单,到目前为止我得到了很好的结果,除了当我执行命令(/wedit)打开它时,表单显示为空白,同时在VS中我确实向表单添加了一些东西。
下面的FrmWorldEdit.Designer.cs
namespace WorldEdit
{
partial class FrmWorldEdit
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listTiles = new System.Windows.Forms.ListView();
this.lblSearch = new System.Windows.Forms.Label();
this.tbxSearch = new System.Windows.Forms.TextBox();
this.btnToggle = new System.Windows.Forms.Button();
this.lblSelected = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// listTiles
//
this.listTiles.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listTiles.Location = new System.Drawing.Point(24, 69);
this.listTiles.Margin = new System.Windows.Forms.Padding(6);
this.listTiles.MultiSelect = false;
this.listTiles.Name = "listTiles";
this.listTiles.Size = new System.Drawing.Size(512, 492);
this.listTiles.TabIndex = 0;
this.listTiles.UseCompatibleStateImageBehavior = false;
this.listTiles.View = System.Windows.Forms.View.List;
this.listTiles.SelectedIndexChanged += new System.EventHandler(this.listTiles_SelectedIndexChanged);
//
// lblSearch
//
this.lblSearch.AutoSize = true;
this.lblSearch.Location = new System.Drawing.Point(19, 28);
this.lblSearch.Name = "lblSearch";
this.lblSearch.Size = new System.Drawing.Size(138, 25);
this.lblSearch.TabIndex = 1;
this.lblSearch.Text = "Search Tiles:";
//
// tbxSearch
//
this.tbxSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tbxSearch.Location = new System.Drawing.Point(163, 26);
this.tbxSearch.Name = "tbxSearch";
this.tbxSearch.Size = new System.Drawing.Size(373, 31);
this.tbxSearch.TabIndex = 2;
this.tbxSearch.TextChanged += new System.EventHandler(this.tbxSearch_TextChanged);
//
// btnToggle
//
this.btnToggle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnToggle.Location = new System.Drawing.Point(24, 617);
this.btnToggle.Name = "btnToggle";
this.btnToggle.Size = new System.Drawing.Size(512, 45);
this.btnToggle.TabIndex = 3;
this.btnToggle.Text = "Start Painting";
this.btnToggle.UseVisualStyleBackColor = true;
this.btnToggle.Click += new System.EventHandler(this.btnToggle_Click);
//
// lblSelected
//
this.lblSelected.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblSelected.AutoSize = true;
this.lblSelected.Location = new System.Drawing.Point(20, 577);
this.lblSelected.Name = "lblSelected";
this.lblSelected.Size = new System.Drawing.Size(197, 25);
this.lblSelected.TabIndex = 4;
this.lblSelected.Text = "Selected Tile: none";
//
// FrmWorldEdit
//
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(564, 685);
this.Controls.Add(this.lblSelected);
this.Controls.Add(this.btnToggle);
this.Controls.Add(this.tbxSearch);
this.Controls.Add(this.lblSearch);
this.Controls.Add(this.listTiles);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Margin = new System.Windows.Forms.Padding(6);
this.Name = "FrmWorldEdit";
this.Text = "World Editor Tool";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmWorldEdit_FormClosing);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListView listTiles;
private System.Windows.Forms.Label lblSearch;
private System.Windows.Forms.TextBox tbxSearch;
private System.Windows.Forms.Button btnToggle;
private System.Windows.Forms.Label lblSelected;
public FrmWorldEdit()
{
}
}
}
您已提供“FrmWorldEdit.Designer.cs”文件的内容
转到“FrmWorldEdit”文件并确保构造函数中有“InitializeComponent”方法调用,如下所示:
public partial class FrmWorldEdit : Form
{
public FrmWorldEdit()
{
InitializeComponent();
}
}
如果决定按照我的建议实施,请不要忘记从“Designer”文件中删除您的构造函数。否则,保持原样,但不要忘记将“InitializeComponent()”方法添加到“Designer.cs”文件中的构造函数中
如果启动Form是空白的并且没有编译错误。 检查您的 Program.cs 文件是否正在运行正确的表单,否则它将运行没有上下文的表单并显示为空白。
在这种情况下,Program.cs 文件应如下所示:
using System;
using System.Windows.Forms;
namespace WorldEdit
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmWorldEdit());
}
}
}
我遇到了这个问题。问题是设计选项卡中的更改未保存。在您的情况下,它将是名为“FrmWorldEdit.cs [Design]”的选项卡。 重新启动 Visual Studio 后,我在设计选项卡中所做的每项更改都消失了,即使我实际上保存了更改。但在我重新启动后,更改已正确保存以供进一步更改。
将来我会尝试添加一个小更改并保存并运行,以确保 Visual Studio 正常工作。如果没有,请重新启动 Visual Studio。