为什么在 C# 中调试时出现空白表单?

2023-11-22

我刚刚摆脱了所有编译器错误。问题之一是我不小心重命名了视觉表单本身,而不是 GUI 上的单个文本框之一。当我去更改代码中弄乱的内容时,它似乎又可以工作了。然而,每当我按 F5 进行调试时,我都会看到一个较小的空白窗口作为我的 GUI,而不是我在 Visual Studio 中设计的窗口。有什么建议么?

这是我的主要(表单)类代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace beehive1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        Worker[] workers = new Worker[4];

        workers[0] = new Worker(new string[] { "Nectar collector", "Honey Manufacturing" });
        workers[1] = new Worker(new string[] { "Egg Care", "Baby Bee Tutoring" });
        workers[2] = new Worker(new string[] { "Hive Maintenance", "Sting Patrol" });
        workers[3] = new Worker(new string[] { "Nectar Collector", "Honey Manufacturing",
            "Egg Care", "Baby Bee Manufacturing", "Hive Maintenance", "Sting Patrol" });


        queen = new Queen(workers);
    }

    Queen queen;

    private void assignJob_Click(object sender, EventArgs e)
    {
        if (queen.AssignWork(workerBeeJob.Text, (int)shifts.Value) == false)
            MessageBox.Show("No Workers Are Available To Do The Job " + workerBeeJob.Text + "", "The Queen Bee Says...");
        else
            MessageBox.Show("The job " + workerBeeJob.Text + " will be done in " + shifts.Value + " shifts", "The Queen Bee Says...");

    }

    private void button2_Click(object sender, EventArgs e)
    {
        report.Text = queen.WorkTheNextShift();
    }
}
}

编辑:设计师代码:

namespace beehive1
{
partial class Form1
{
    /// <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.shiftLabel = new System.Windows.Forms.Label();
        this.workerBeeJob = new System.Windows.Forms.ComboBox();
        this.jobLabel = new System.Windows.Forms.Label();
        this.shifts = new System.Windows.Forms.NumericUpDown();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.assignJob = new System.Windows.Forms.Button();
        this.nextShift = new System.Windows.Forms.Button();
        this.report = new System.Windows.Forms.TextBox();
        ((System.ComponentModel.ISupportInitialize)(this.shifts)).BeginInit();
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();
        // 
        // shiftLabel
        // 
        this.shiftLabel.AutoSize = true;
        this.shiftLabel.Location = new System.Drawing.Point(287, 26);
        this.shiftLabel.Name = "shiftLabel";
        this.shiftLabel.Size = new System.Drawing.Size(33, 13);
        this.shiftLabel.TabIndex = 0;
        this.shiftLabel.Text = "Shifts";
        // 
        // workerBeeJob
        // 
        this.workerBeeJob.FormattingEnabled = true;
        this.workerBeeJob.Location = new System.Drawing.Point(27, 42);
        this.workerBeeJob.Name = "workerBeeJob";
        this.workerBeeJob.Size = new System.Drawing.Size(121, 21);
        this.workerBeeJob.TabIndex = 1;
        // 
        // jobLabel
        // 
        this.jobLabel.AutoSize = true;
        this.jobLabel.Location = new System.Drawing.Point(24, 26);
        this.jobLabel.Name = "jobLabel";
        this.jobLabel.Size = new System.Drawing.Size(84, 13);
        this.jobLabel.TabIndex = 2;
        this.jobLabel.Text = "Worker Bee Job";
        // 
        // shifts
        // 
        this.shifts.Location = new System.Drawing.Point(290, 42);
        this.shifts.Name = "shifts";
        this.shifts.Size = new System.Drawing.Size(74, 20);
        this.shifts.TabIndex = 3;
        // 
        // groupBox1
        // 
        this.groupBox1.Controls.Add(this.assignJob);
        this.groupBox1.Controls.Add(this.shiftLabel);
        this.groupBox1.Controls.Add(this.workerBeeJob);
        this.groupBox1.Controls.Add(this.jobLabel);
        this.groupBox1.Controls.Add(this.shifts);
        this.groupBox1.Location = new System.Drawing.Point(32, 12);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(384, 150);
        this.groupBox1.TabIndex = 4;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "Worker Bee Job Assignments";
        // 
        // assignJob
        // 
        this.assignJob.Location = new System.Drawing.Point(27, 70);
        this.assignJob.Name = "assignJob";
        this.assignJob.Size = new System.Drawing.Size(121, 23);
        this.assignJob.TabIndex = 4;
        this.assignJob.Text = "Assign This Job";
        this.assignJob.UseVisualStyleBackColor = true;
        this.assignJob.Click += new System.EventHandler(this.assignJob_Click);
        // 
        // nextShift
        // 
        this.nextShift.Location = new System.Drawing.Point(422, 38);
        this.nextShift.Name = "nextShift";
        this.nextShift.Size = new System.Drawing.Size(79, 77);
        this.nextShift.TabIndex = 5;
        this.nextShift.Text = "Work The Next Shift";
        this.nextShift.UseVisualStyleBackColor = true;
        this.nextShift.Click += new System.EventHandler(this.button2_Click);
        // 
        // report
        // 
        this.report.Location = new System.Drawing.Point(32, 199);
        this.report.Multiline = true;
        this.report.Name = "report";
        this.report.Size = new System.Drawing.Size(384, 157);
        this.report.TabIndex = 6;
        // 
        // Form
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(539, 398);
        this.Controls.Add(this.report);
        this.Controls.Add(this.nextShift);
        this.Controls.Add(this.groupBox1);
        this.Name = "Form";
        this.Text = "Beehive Management System";
        ((System.ComponentModel.ISupportInitialize)(this.shifts)).EndInit();
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.Label shiftLabel;
    private System.Windows.Forms.ComboBox workerBeeJob;
    private System.Windows.Forms.Label jobLabel;
    private System.Windows.Forms.NumericUpDown shifts;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.Button assignJob;
    private System.Windows.Forms.Button nextShift;
    private System.Windows.Forms.TextBox report;
}
}

也许应用程序不再连接到该 Form 类?我尝试过 Clean Build 和 ReBuild,但似乎不起作用。


空白表格意味着InitializeComponent()未激活或this.Controls.Add没有正确添加控件。尝试逐步调试并激活所有 CLR 异常以确保构造函数中没有发生异常。还向我们展示了表格的构造。

Edit: alt text

应该检查这一点,而不是像上面那样检查。 现在在调试模式下运行您的表单并查看是否发生任何异常。 请添加您如何称呼您的表格含义:

Form1 newForm=new Form1();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么在 C# 中调试时出现空白表单? 的相关文章

随机推荐

  • 带按钮的自定义 MKAnnotation 标注气泡

    我正在开发应用程序 用户通过 GPS 进行本地化 然后询问他是否位于特定位置 为了确认这一点 标注气泡会立即呈现给他 询问他是否在特定位置 As there is alot of similar questions I was able t
  • 关于如何将 UpdateSourceTrigger=Explicit 与 MVVM 结合使用的一个很好的示例

    我试图弄清楚如何使用 UpdateSourceTrigger Explicit 我有以下表格
  • 如何修复模板内重构 decltype 错误

    edit可能无法完成 请参阅采用函数指针的函数模板的干净实现虽然答案 1 有一个 C 宏解决方法https stackoverflow com a 18706623 2332068 我将函数传递到模板中以成为构造函数的预先提供的参数 但还需
  • Gradle:多维风味 ApplicationId

    我有一个相对复杂的项目 每个应用程序需要两个风味维度 我在下面的示例中更简单地重写了它 flavorDimensions shape color productFlavors blue flavorDimension color red f
  • 动态加载样式表

    我知道您可以在页面头部放置样式表 但我喜欢将它们放在单独的文件中 现在我正在使用单页应用程序 那么 SPA 中的内容是动态的 对吗 所以我不想用链接标签导入头部的所有样式表 我可以在需要时以某种方式导入样式表吗 我的意思是 我可以在正文中添
  • 如何在没有 --set-upstream 的情况下推送远程服务器上不存在的新分支?

    情况是我在远程服务器上没有存储库 只有一个帐户 然后 我在本地运行以下命令 其中x是用户名并且y是仅存在于我的本地系统上的项目名称 git init git remote add buckety https email protected
  • su 将密码传递给脚本

    我正在尝试编写一个将运行以下命令的脚本 sudo su runmqsc result su c runmqsc QMGR lt home rob query queue txt m mqm 然而 我的问题是 这些命令是由 sudoers 文
  • 在c#中创建接口的实例

    我在 C 中使用接口 而不是编写一个实现该接口的全新类 是否可以只创建一个实现该接口的对象 接口定义为 public interface ITokenStore IToken CreateRequestToken IOAuthContext
  • 在 mongo 中插入具有数组大小的字段

    我在 mongodb 中有一个文档 其中包含一些数组 现在我需要一个包含该数组的项目数量的字段 所以我需要更新添加此字段的文档 只是我认为这会起作用 db myDocument update itemsTotal exists false
  • Angular:选择性编译模板

    我知道ng non bindable允许给定元素及其子元素不编译为模板 它似乎被设计为根据需要散布在整个模板中 有没有办法告诉 Angular 不要处理给定的元素 而是 戳洞 并允许处理选定的子元素 例如 我希望能够做这样的事情 div d
  • 如何在Android Studio中设置Java SDK路径?

    我安装了 Java 1 7 0 21 今天在卸载以前的版本后安装了 1 7 0 45 现在Android Studio已停止编译项目并表示无法找到1 7 0 21文件夹 如何设置Java SDK的新路径 我也更改了环境变量 但没有用 最高至
  • 如何使用 DOM Inspector(或类似工具)检查我的独立 Xul 应用程序?

    我正在尝试检查我的独立 Xul 应用程序 但是DOM 检查器的页面仅讨论浏览器上加载的文档 如何检查我的独立 Xul 应用程序 DOM Inspector 只能检查其主机应用程序 它扩展的应用程序 中的文档 然后只能检查它安装到的配置文件
  • Python getpass.getpass() 函数调用挂起

    我试图收到询问我密码的提示 但是当我尝试拨打电话时getpass getpass 它只是冻结了 我在 Windows 7 64 位上运行 在 Canopy 上使用 Python 2 7 import sys import getpass p
  • 可以在“设置”>“辅助功能”中检测粗体文本设置吗?

    使用 iOS 7 可以对您的应用程序进行编码 以尊重用户对动态类型的设置 更大或更小的字体大小 你用的方法preferredFontForTextStyle 然后监听通知 以便在用户在应用程序运行时更改设置时更新 UI 我想知道是否可以使用
  • 在 input.checked=true/false _without_ jQuery 上触发事件

    考虑以下代码 http jsfiddle net FW36F 1
  • 使用 Google Drive API 将文件复制到特定的父文件夹中?

    我正在使用 Python 2 7 和服务帐户根据文件标题将 Google 云端硬盘中的文件复制到另一个文件夹中 这需要我执行五 5 个命令 按标题查找文件 ID files list 按标题查找父文件夹 ID files list 复制文件
  • Firefox 跨域请求

    我需要从在 Firefox 中运行的脚本发出跨域请求 仅用于开发目的 这能实现吗 也许修改about config keys Thanks 有一个很棒的帖子詹姆斯 帕多尔西关于如何使用 jQuery 跨域请求 但该帖子也有非常好的资源 需要
  • 如何抑制 HBase 客户端应用程序中的 INFO 日志?

    我正在编写一个访问 HBase 的 Java 控制台应用程序 但我不知道如何摆脱所有烦人的 INFO 消息 13 05 24 11 01 12 INFO zookeeper ZooKeeper Client environment zook
  • 如何在 iPhone 上将 NSMutableArray 转换为 CSV 文件?

    我正在编写一个 iPhone 应用程序 其中包含一个函数 它可以将 NSMutableArray 转换为 CSV 文件 但是 我不知道该怎么办 谁能帮我做到这一点 非常感谢 更新 谢谢大家的回复 实际上 数组包含元素的对象 但我可以将其全部
  • 为什么在 C# 中调试时出现空白表单?

    我刚刚摆脱了所有编译器错误 问题之一是我不小心重命名了视觉表单本身 而不是 GUI 上的单个文本框之一 当我去更改代码中弄乱的内容时 它似乎又可以工作了 然而 每当我按 F5 进行调试时 我都会看到一个较小的空白窗口作为我的 GUI 而不是