본문 바로가기

C#

(12)
[C#] 레지스트리(Registry) 저장 로그인 아이디와 같은 간단한 사용자 정보는 레지스트리에 등록하여 사용가능 프로그램이 업데이트 되어도 사용자 정보는 그대로 사용할 경우 유용 private const string c_RegistryKey = @"Software\Ungs"; // 상위 경로는 HKEY_CURRENT_USER 로 자동 설정 // 레지스트리 저장시 RegistryKey regKey = Registry.CurrentUser.CreateSubKey(c_RegistryKey) regKey.SetValue("UserId", "입력데이터"); // 레지스트리 출력 RegistryKey regKey = Registry.CurrentUser.OpenSubKey(c_RegistryKey); if (regKey != null){ string t..
[C#] CheckForIllegalCrossThreadCalls 크로스스레드 Control.CheckForIllegalCrossThreadCalls = false; // 멀티 스레드에서도 다른 스레드의 컨트롤에 접근 가능oss 스레드간 컨트롤 호출에 대한 예외를 무시 안정성을 고려한다면 사용하지 않는것을 추천 (체크로직을 구현하지 않을 경우)
[C#] TopMost 폼 여러개일 경우 가장 위로 설정 TopMost는 말그대로 최상위라는 의미 이 속성을 이용 하면 폼을 응용 프로그램의 맨위 폼으로 표시할지 여부를 나타내는 값을 가져오거나 설정 가능 맨 위 폼은 활성 폼이나 전경 폼이 아닌 경우에도 다른 모든 폼과 겹치는 폼을 의미 때문에 Windows의 DeskTop상에 서로 다른 응용프로그램을 사용중이라면 이 속성이 true인 폼은 모든 응용프로그램의 맨위에 위치 해당 프로그램의 앞쪽에 표시하고 싶다면 Owner이라는 속성을 이용 ex) 메모장 찾기폼을 이용중 익스플로러창을 띄웠다면 익스플로러창의 앞쪽에 표시 메모장을 활성화시켰을 경우 찾기폼은 메모장 앞쪽에 위치 사용 방법은 다음 예제코드를 참고 subForm sFrm = new subForm(); sFrm.Owner = this; //이 부분 추가..
[C#] Form 호출 form 호출(A Form → B Form) 1. A Form을 Show()로 호출 2. A Form의 Form_Closing Event에서 B Form의 Delegate매서드 호출
[C#] Invoke, InvokeRequired delegate void AddList(); public void Add_cross(){ try{ if (this.InvokeRequired){ //다른 스레드에서 접근이 필요하면 AddList d = new AddList(Add_cross); this.Invoke(d, new object[] {}); }else Add_lstView_Room(strId, strRTitle, strRMaxUser, strOpenRoom); }catch (Exception ex){ wnd.Add_MSG("List 크로스 오류: " + ex.Message); } }
[C#] DB연결 SQLConnection SqlConn = new SqlConnection("server=localhost;uid=sa;pwd=ssss; database=OurI"); SqlConn.Open(); string Sqlstr = "select Password from Login where Id = " + "'" + Form_Login.LoginID + "'"; SqlComm = new SqlCommand(Sqlstr, SqlConn); SqlConn = new SqlConnection("server=localhost;uid=sa;pwd=ssss;database=OurI"); SqlConn.Open(); string Sqlstr = "Insert Login values('" + Form_UserCreate.CreateName + "'..
[C#] KeyPress / KeyDown 이벤트 (Enter 입력) private void txt_Id_KeyPress(object sender, KeyPressEventArgs e){ if (e.KeyChar == (char)Keys.Enter){ txt_Pwd.Focus(); //textbox.Focus(); } } private void newText_KeyDown(object sender, KeyEventArgs e){ if (e.KeyCode == Keys.Enter) button1_Click(sender, e); }
[C#] 폼의 X버튼 클릭시 확인 메세지 생성 DialogResult result; result = MessageBox.Show("종료하시겠습니까?", "confirm/cancel", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if(result == DialogResult.Yes){ this.Close(); }else{ LoginStart(); //이전 폼 호출하는 메서드 }