在C#中调试时为什么会得到空白表格? [英] Why do I get a blank form when I debug in C#?

查看:63
本文介绍了在C#中调试时为什么会得到空白表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i just got rid of all my compiler errors. One of the problems was that I accidentally renamed the visual form itself instead of one of the individual text boxes on my GUI. When I went to change what I had messed up in the code, it seemed to be working again. However, whenever I hit F5 to debug, I get a smaller, blank window as my GUI, and not the one that I had designed in Visual Studio. Any suggestions?

这是我的主要(窗体)类代码:

Here's my main (Forms) class code:

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类连接?我尝试了干净构建"和重新构建",但似乎没有用.

Maybe the application is no longer connected to that Form class? I've tried a Clean Build and a ReBuild, but it hasn't seemed to work.

推荐答案

空白格式表示未接受 InitializeComponent() this.Controls.Add 无效"t正确添加控件.尝试逐步调试并激活所有CLR异常,以确保构造函数中没有异常发生.也向我们展示表单的构造.

Blank form means that InitializeComponent() isn't acivated or this.Controls.Add doesn't add the controls properly. try to debug step by step and activate all CLR exception to make sure no exception is occuring in the constructor. show us the construction of the form also.

不应该检查此项目,如上所示.现在以调试模式运行您的表单,看看是否有异常发生.请添加您的表单称呼含义:

this should be checked not checked of as seen above. now run your form in debug mode and see if any excecptions occur. please add how you call your form meaning:

Form1 newForm=new Form1();

这篇关于在C#中调试时为什么会得到空白表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆