IT/C#

C# - [winform] MDI프로젝트에서 로그인폼 만들기

!? 2022. 2. 10.

1. visual studio에서 winform 프로젝트 생성 후 Mdi창 추가

 

 

 

 

2. login 폼 추가

  1) login 폼은 간단하게 아이디/패스워드 입력할 수 있도록 간단하게 만듦

3. login 폼 디자인

  1) login 폼은 폼같이 보이면 이쁘지 않아 FormBorderStyle 속성을 None으로 변경

  2) 아이디/비밀번호 입력할 수 있는 TextBox와 확인/취소 버튼 만듦

  3) login 폼 보일 시 화면 중앙에 나타날 수 있도록 StartPosition 속성을 CenterScreen으로 변경

  4) mdi폼은 전체화면으로 보이는게 좋기때문에 WindowState 속성을 Maximized으로 변경

 

 

 

 

 

4. Program.cs파일에서 로그인창 호출과 mdiForm 호출 추가

  1) 로그인창에서 확인 클릭 시 DialogResult.OK 넘겨 mdi창 나오도록 함.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace mdiLoginTest
{
    static class Program
    {
        /// <summary>
        /// 해당 애플리케이션의 주 진입점입니다.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // 로그인창 추가
            loginForm loginPopup = new loginForm();
            DialogResult Result = loginPopup.ShowDialog();

            if (Result != DialogResult.OK)
                return;

            Application.Run(new mdiTest());
        }
    }
}

5. login폼에서 확인/취소 이벤트 추가

  1) 확인 클릭시 DialogResult.OK 추가 하고 폼을 닫음.

  2) 취소 클릭시 폼을 닫음.

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 mdiLoginTest
{
    public partial class loginForm : Form
    {
        public loginForm()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

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

간단하게 mdi폼으로 로그인할 수 있게 만들었는데,

DB에서 로그인정보를 불러와서 체크하는 부분과

DB에서 Menu를 불러와서 Mdi폼에서 나타내주면 기본적인 프로젝트가 되지 않을까 함.

'IT > C#' 카테고리의 다른 글

C# - 특정 Control 찾아서 초기화  (0) 2023.08.18
C# - ClickOnce 버전 보이기  (0) 2022.02.18
C# - Dapper로 MS-SQL DB 처리하기  (0) 2022.02.14
C# - log4net 적용하기  (0) 2022.02.08
C# - [Winform] 중복실행 방지  (0) 2022.02.07

댓글