C#:当我运行程序并且Visual Studio试图创建一个新类时,第二个表单没有加载

本文关键字:一个 新类时 第二个 加载 表单 创建 运行 程序 Studio Visual | 更新日期: 2023-09-27 18:21:49

我一直在开发这个非常简单的程序,该程序使用组合框和列表来显示"书籍",允许打印和预览,作业告诉我创建一个表单"关于表单",这是一个在单击"关于"选项卡时加载的表单。但每次我点击它,VS都会创建一个新的类,我就会得到这个

"未实现异常"

错误,尽管程序没有任何错误。不知道为什么Visual Studio试图为"about form"创建一个新的类/代码,尽管我已经创建了它。我认为通过VS生成东西会有所帮助,但程序仍然不能正常工作。

这是我的关于表单代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CS10AboutForm.cs
{
    public partial class frmAbout : Form
    {
        public frmAbout()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

当我尝试加载表单时,我得到的错误和VS创建的类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CS10.cs
{
    class frmAbout
    {
        internal void ShowDialog()
        {
            throw new NotImplementedException();
        }
    }
}

我的另一个使用"about"表单的表单的代码:

namespace CS10.cs
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void lblEdit_Click(object sender, EventArgs e)
        {
        }
        private void menuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
        }
        private void addBookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Add a new book to the list
            if (cboBooks.Text != "")
            {
                cboBooks.Items.Add(cboBooks.Text);
                cboBooks.Text = "";
            }
            else
            {
                MessageBox.Show("Enter a book to add", "Missing data",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            cboBooks.Focus();
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }
        private void mnuEditRemove_Click(object sender, EventArgs e)
        {
            // Remove the selected book from the list
            if (cboBooks.SelectedIndex != -1)
            {
                cboBooks.Items.RemoveAt(cboBooks.SelectedIndex);
            }
            else
            {
                MessageBox.Show("First select a book to remove",
                    "No selection made", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void mnuEditClear_Click(object sender, EventArgs e)
        {
            // Clear the book list
            DialogResult responseDialogResult;
            responseDialogResult = MessageBox.Show("Clear the book list?",
                "Clear book list", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (responseDialogResult == DialogResult.Yes)
            {
                cboBooks.Items.Clear();
            }
        }
        private void mnuEditCount_Click(object sender, EventArgs e)
        {
            // Display a count of the books on the list
            MessageBox.Show("The number of book types is " + cboBooks.Items.Count.ToString());
        }
        private void mnuHelpAbout_Click(object sender, EventArgs e)
        {
            // Create an instance and display frmAbout 
            frmAbout frmAboutObj = new frmAbout();
            frmAboutObj.ShowDialog();   //.ShowDialog displays as a Model Form
        }
        private void mnuFileExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void mnuFilePrintPreview_Click(object sender, EventArgs e)
        {
            // Begin print preview by assigning PrintDocument
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }
        private void mnuFilePrint_Click(object sender, EventArgs e)
        {
            // Print by calling the Print method
            printDocument1.Print();
        }
        private void printDocument1_PrintPage(object sender,
               System.Drawing.Printing.PrintPageEventArgs e)
        {
            // Handle printing and print previews
            // printPreviewDialog1.ShowDialog() and printDocument1.Print() trigger
            //  PrintPage event.
            Font printFont = new Font("Arial", 12);
            Font headingFont = new Font("Arial", 14, FontStyle.Bold);
            float fltLineHeight = printFont.GetHeight();
            float fltPrintX = e.MarginBounds.Left;
            float fltPrintY = e.MarginBounds.Top;
            string strPrintLine;
            // Print Headings
            strPrintLine = "Book List ";
            e.Graphics.DrawString(strPrintLine, headingFont,
                Brushes.Black, fltPrintX, fltPrintY);
            strPrintLine = "By Lina";
            fltPrintY += fltLineHeight;
            e.Graphics.DrawString(strPrintLine, headingFont,
                Brushes.Black, fltPrintX, fltPrintY);
            // Leave a blank line between heading and detail line
            fltPrintY += fltLineHeight * 2;
            // Loop through the entire list
            for (int intIndex = 0; intIndex <= cboBooks.Items.Count - 1; intIndex++)
            {
                // Set up a line
                strPrintLine = cboBooks.Items[intIndex].ToString();
                // Send the line to the graphics page object
                e.Graphics.DrawString(strPrintLine, printFont,
                    Brushes.Black, fltPrintX, fltPrintY);
                // Increment the Y position for the next line
                fltPrintY += fltLineHeight;
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void printPreviewDialog1_Load(object sender, EventArgs e)
        {
        }
        private void mnuFileExit_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }
        private void mnuFilePrint_Click_1(object sender, EventArgs e)
        {
            // Call the print process by calling the Print method
            printDocument1.Print();
        }
        private void mnuFilePrintPreview_Click_1(object sender, EventArgs e)
        {
            // Begin print preview by assigning PrintDocument
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }
        private void mnuEditRemove_Click_1(object sender, EventArgs e)
        {
             // Remove the selected book from the list
            if (cboBooks.SelectedIndex != -1)
            {
                cboBooks.Items.RemoveAt(cboBooks.SelectedIndex);
            }
            else
            {
                MessageBox.Show("First select a book to remove",
                    "No selection made", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

        }
        private void mnuEditClear_Click_1(object sender, EventArgs e)
        {
            // Clear the book list
            DialogResult responseDialogResult;
            responseDialogResult = MessageBox.Show("Clear the book list?",
                "Clear book list", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (responseDialogResult == DialogResult.Yes)
            {
                cboBooks.Items.Clear();
            }
        }
        private void mnuEditCount_Click_1(object sender, EventArgs e)
        {
            // Display a count of the books on the list
            MessageBox.Show("The number of book types is " + cboBooks.Items.Count.ToString());
        }
        private void mnuHelpAbout_Click_1(object sender, EventArgs e)
        {
            frmAbout frmAboutObj = new frmAbout();
            frmAboutObj.ShowDialog();   //.ShowDialog displays as a Modal Form
        }       
    }
}

同样,生成一些代码是因为它看起来可以解决问题,所以如果代码太乱或太长,我深表歉意。请帮忙?非常感谢。

C#:当我运行程序并且Visual Studio试图创建一个新类时,第二个表单没有加载

在frmAbout.ShowDialog()中清除throw new NotImplementedException();

我决定从头开始,并重新使用了我的大部分代码。问题是我加错了"关于表格";我应该选择项目>添加表单,而不是开始一个全新的项目。此外,我最初是以"关于表格"的形式开始这个项目的,因为我误读了说明书。