【问题标题】:Form is not rendering in Visual Studio 2019表单未在 Visual Studio 2019 中呈现
【发布时间】:2020-11-17 22:58:02
【问题描述】:

我一直在使用 Visual Studio 2019 中的表单制作简单的十进制到二进制/八进制/十六进制转换器,但发生了一些奇怪的事情。

我在Form1.cs[Design] 中创建了一个表单,只需拖放几个文本字段、3 个按钮和几个标签。看起来不错。然后我点击按钮并转到Form1.cs 添加一些编程逻辑。当我点击返回Form1.cs [Design] 时,我看到了:

没有可见的按钮或文本字段。如果我尝试再次拖放一个按钮,这就是我得到的:

所以我添加的按钮在那里,它们只是没有呈现? 当我尝试 Ctrl+F5 时,没有错误,它会构建,但表单看起来也是空白的。

这是来自Form1.cs的代码,

using System; using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            long number = long.Parse(textBox1.Text);
            string Base = Convert.ToString(number, 2);
            textBox2.Text = Base;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            long number = long.Parse(textBox1.Text);
            string Base = Convert.ToString(number, 8);
            textBox2.Text = Base;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            long number = long.Parse(textBox1.Text);
            string Base = Convert.ToString(number, 16);
            textBox2.Text = Base;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    } }

唯一非自动生成的代码是附加在按钮上的代码。

Form1_Load 方法是自动生成的,我认为问题出在它身上?不过我并不完全了解它的功能。

任何帮助将不胜感激。

【问题讨论】:

  • 这是 .net core 3.x 还是完整的 .net 框架项目?
  • 嘿,我刚刚在创建项目时选择了一个“Windows Forms App (.Net Core)”。我真的只想要一个简单的 WinForm。不是一个完整的项目,不。而且我使用的是最新的 .Net Core 版本,所以我相信它是 3.1.302。
  • Form1.Designer.cs 文件出现问题,我们看不到。我们可以看到它的选项卡,并且它已更改,请确保永远不要自己编辑此文件。 .NETCore 设计器支持仍在进行中,因此建议选择 (.NET Framework) 项目模板。
  • 我认为你没有足够关注@HansPassant 的其余部分评论:Something went wrong with the Form1.Designer.cs file ... .NETCore designer support is still work-in-progress so picking the (.NET Framework) project template is recommended
  • WinForms 设计器对.net core 3.1 based projects is still in preview state 的支持以及一些功能缺失。微软希望通过 .net 5 发布designer with all features

标签: c# visual-studio winforms .net-core visual-studio-2019


【解决方案1】:

某些控件具有相同的名称。检查一下

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-20
    • 2020-02-04
    • 2023-01-24
    • 2021-06-20
    • 2022-06-16
    • 2021-02-04
    • 2020-03-17
    • 1970-01-01
    相关资源
    最近更新 更多