안녕하세요, 달님입니다!
최근 로그인 관련 프로그램을 만들게 되어서 작업 하고 있는데요.
작업 진행하다 함께 알아두면 좋을것 같아 공유합니다.

로그인ID 저장하여 사용하기 : Properties.Settings 이용하기
로그인창을 만들 때, ID기억하기 혹은 ID 저장하기를 체크하여 사용하는 경우가 많을건데요.
Registry를 이용할 수도 있지만 좀 더 간단한 방법으로 설정할 수 있습니다.
properties.Setting을 이용하면 현재 상태의 설정값을 저장하여 다음 번에 Load할 때 불러 사용 할 수 있습니다.
1. [솔류션 탐색기] - [Properties] 선택 후 Settings.settings 더블 클릭
Properties의 Settings.settings를 더블 클릭하면, 오른쪽에 해당 화면이 나타납니다.
2. Settings.setting 에서 필요한 값 입력
저의 경우, 체크 상태에 따른 사용자 ID값과 윈도우 실행 시 로그인 창이 자동 실행 되기 위해 필요한 값을 입력해 주었습니다.
chk_Remember : [UserID 저장] 체크값
chk_AutoEXE : [윈도우 실행 시 자동 실행] 체크값
LoginIDSave : Login ID 입력 값
3. Form이 Load 될 때 / Closing 될 때 코드 추가
Load 시
private void AutoLogin_Load(object sender, EventArgs e)
{
txt_UserID.Text = Properties.Settings.Default.LoginIDSave;
chk_AutoEXE.Checked = Properties.Settings.Default.chk_AutoEXE;
chk_Remember.Checked = Properties.Settings.Default.chk_Remember;
}
Closing시
private void AutoLogin_FormClosing(object sender, FormClosingEventArgs e)
{
if (chk_AutoEXE.Checked && chk_Remember.Checked)
{
Properties.Settings.Default.chk_Remember = true;
Properties.Settings.Default.chk_AutoEXE = true;
Properties.Settings.Default.LoginIDSave = this.LoginID;
}
else if (!chk_AutoEXE.Checked && !chk_Remember.Checked)
{
Properties.Settings.Default.chk_Remember = false;
Properties.Settings.Default.chk_AutoEXE = false;
Properties.Settings.Default.LoginIDSave = string.Empty;
}
Properties.Settings.Default.Save();
Application.Exit();
}
위 예시는 참고용일 뿐, 자기 입맛에 맞추어 작성해 주면 됩니다.
실행해 보면, 체크값에 따라 아래와 같이 보여지는 것을 확인할 수 있습니다.
'공부 (IT) > IT관련_C#' 카테고리의 다른 글
[문법] 문자열 공백제거 (Trim/TrimStart/TrimEnd/Replace) (10) | 2022.04.28 |
---|---|
[오류] 프로그램에는 진입점에 적합한 정적 'main' 메서드가 포함되어 있지 않습니다. (8) | 2022.03.04 |
[오류] System.BadImageFormatException 발생 및 처리 방법 (0) | 2021.08.17 |
댓글