首页 > 解决方案 > 当我运行代码时,Windows 窗体未在 csharp 中显示

问题描述

我正在使用访问创建一个数据库,突然间,当我运行代码时,我的表单没有显示。不久前它还在显示表单,但现在不是了。顺便说一句,我没有接触或弄乱 program.cs 文件。下面是program.cs文件:

namespace P1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

    }
}

如果有帮助,下面是我的数据库代码。我什至削减了一些代码,但它根本没有显示表单。但是,它表明程序的构建没有错误。

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;
using System.Data.OleDb;

namespace P1
{

    public partial class Form1 : Form
    {          
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source =d:\DDBS.mdb");
        OleDbDataAdapter adap = new OleDbDataAdapter(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source =d:\DDBS.mdb","select * from Student");
        DataTable d2 = new DataTable();
        DataSet d1 = new DataSet("Student");

        public Form1()
        {
            InitializeComponent();               
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dDBSDataSet.Student' table. You can move, or remove it, as needed.
            //this.studentTableAdapter.Fill(this.dDBSDataSet.Student);

        }

        private void display_btn_Click(object sender, EventArgs e)
        {
            adap.Fill(d2);
            dataGrid3.DataSource = d2;
        }
        private void dataGrid1_Navigate(object sender, NavigateEventArgs ne)
        {
        }
        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void form2_btn_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            f3.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            f4.Show();
        }

        private void next_btn_Click(object sender, EventArgs e)
        {
        }

        private void dataGrid2_Navigate(object sender, NavigateEventArgs ne)
        {

        }

        private void dataGrid3_Navigate(object sender, NavigateEventArgs ne)
        {

        }
    }
}

表单的设置输出类型: 表单的设置输出类型

标签: c#winforms

解决方案


我认为您的问题是您的设置输出类型是控制台应用程序或类库。您应该更改为申请表。

在此处输入图像描述


推荐阅读