skip to Main Content

I’m working on our little project and when I saved my work and exit on Visual Studio. I found that the designer wasn’t showing up, and it’s just a bunch of code, then there was this LoginForm.Designer.cs file. My problem is how can I make the designer show up again because I have to customize more on the UI of the project

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:UsersacerDocumentsdbIMS.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);
            }
        }
    }
}

This is the code on my LoginForm.cs

I tried different solutions on YouTube and google like shift +f7 but it’s still not showing up

2

Answers


  1. My problem is how can I make the designer show up again

    VS2022 is a bit buggy with the WinForm designer. Not the ideal solution but you can fix it by commenting out all the code in the Form1.cs except for :

    public LoginForm()
    {
      InitializeComponent();
    }
    

    Goto Definition of InitializeComponent() and look for all the red dots on the right margin, mainly Event += Handlers and comment these out.

    Now view the form designer. Bit by bit bring back the events in the form1.designer.cs and uncomment the corresponding events in the form1.cs

    The trick is to narrow down the problem.

    Login or Signup to reply.
  2. FWIW: I was having this problem with one of my forms and I determined that it was because I had an additional class defined within the form. Once I moved that class into it’s own file, my problem went away.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search