我正在处理我们的小项目,当我保存我的工作并退出 Visual Studio 时。我发现设计者没有出现,只是一堆代码,然后就是这个
LoginForm.Designer.cs
文件。我的问题是如何让设计师再次出现,因为我必须在项目的 UI 上自定义更多内容
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace InventoryManagementSystem
{
public partial class LoginForm : Form
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\acer\Documents\dbIMS.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cm = new SqlCommand();
SqlDataReader dr;
public LoginForm()
{
InitializeComponent();
}
private void checkBoxPass_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxPass.Checked == false)
txtPass.UseSystemPasswordChar = true;
else
txtPass.UseSystemPasswordChar = false;
}
private void lblClear_Click(object sender, EventArgs e)
{
txtName.Clear();
txtPass.Clear();
}
private void pictureBoxClose_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Exit Applicaton", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Application.Exit();
}
}
private void btnLogin_Click(object sender, EventArgs e)
{
try
{
cm = new SqlCommand("SELECT * FROM tbUser WHERE username=@username AND password=@password", con);
cm.Parameters.AddWithValue("@username", txtName.Text);
cm.Parameters.AddWithValue("@password", txtPass.Text);
con.Open();
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
MessageBox.Show("Welcome " + dr["fullname"].ToString() + " | ", "ACCESS GRANTED", MessageBoxButtons.OK, MessageBoxIcon.Information);
MainForm main = new MainForm();
this.Hide();
main.ShowDialog();
}
else
{
MessageBox.Show("Invalid username or password!", "ACCESS DENITED", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
这是我的 LoginForm.cs 上的代码
我在 YouTube 和谷歌上尝试了不同的解决方案,比如 shift +f7 但它仍然没有出现
FWIW:我的一个表单遇到了这个问题,我确定这是因为我在表单中定义了一个额外的类。一旦我将该类移动到它自己的文件中,我的问题就消失了。
我的问题是怎样才能让设计师再次出现
VS2022 的 WinForm 设计器有点问题。这不是理想的解决方案,但您可以通过注释掉 Form1.cs 中的所有代码来修复它,除了:
public LoginForm()
{
InitializeComponent();
}
转到 InitializeComponent() 的定义并查找右边空白处的所有红点,主要是 Event += Handlers 并将它们注释掉。
现在查看表单设计器。一点点带回form1.designer.cs中的事件,取消form1.cs中对应事件的注释
诀窍是缩小问题范围。