123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Collections;
- using Janus.Windows.UI.CommandBars;
- namespace IControls_FireManager
- {
- // 폼생성에 관련된 함수는 여기 클래스에서 전담한다
- public static class _Form
- {
- // 중복 생성 방지용 해쉬테이블 (폼이름, 폼)
- public static Hashtable CreatedForm = new Hashtable();
- // 폼 생성하기
-
- // 폼을 닫는 이벤트는 2가지이다
- // 이벤트1 : 생성된 폼에서 오른쪽 상단 닫기 아이콘을 클릭해서 폼 닫는 경우 -> CreateForm.FormClosing
- // 이벤트2 : 다른 폼에서 현재 생성된 폼을 닫기하라고 명령하는 경우 -> _Event.FormClose_SendMessage_Event
- // UIcommand 메뉴바 체크 상태 구현 : UICommand 가 null 이면 메뉴바에서 생성된 폼이 아닌것으로 간주함
- public static void Create(Form CreateForm, UICommand UIcommand)
- {
- // 폼이름을 키로 함. 결국 폼이름으로 검색
- if (CreatedForm.Contains(CreateForm.Name) == true)
- {
- // 이미 생성된 폼이라면 포커스를 준다
- // 파라미터는 동적생성한 폼이므로 파라미터의 속성을 접근해서는 안된다.
- foreach (DictionaryEntry de in CreatedForm)
- {
- if (CreateForm.Name == de.Key.ToString())
- {
- // 최대화 혹은 최소화 된 창을 일반으로 돌리고 포커스를 줌
- ((Form)de.Value).WindowState = FormWindowState.Normal;
- ((Form)de.Value).Focus();
- break;
- }
- }
- }
- else
- {
- // 폼이름(Form 속성의 Name 이 Key 값이다. 리스트에 추가함
- CreatedForm.Add(CreateForm.Name,CreateForm);
- // 이벤트1 : 생성된 폼에서 오른쪽 상단 닫기 아이콘을 클릭해서 폼 닫는 경우
- _Event.FormClose_SendMessage_Event +=new _Event.FormClose_SendMessage_Handler(_Event_FormClose_SendMessage_Event);
- // 이벤트2 : 다른 폼에서 현재 생성된 폼을 닫기하라고 명령하는 경우
- CreateForm.FormClosing +=new FormClosingEventHandler(CreateForm_FormClosing);
- // 새창 출력시 맨앞으로 보이게함
- //debug CreateForm.TopMost = true;
- // 보이기
- CreateForm.Show();
- // 옵션 (추가하고 싶은 옵션은 여기에서 처리)
- CreateForm.StartPosition = FormStartPosition.WindowsDefaultLocation;
- // 메인폼의 메뉴바에서 체크 표시
- if (UIcommand != null )
- {
- UIcommand.IsChecked = true;
- CreateForm.Tag = UIcommand;
- }
- // Log
- _Event.DebugView_SendMessage_Write(CreateForm.Name + _Text.Blank + _Text.LOG_CreateForm);
- }
- }
- // 이벤트1 : 생성된 폼에서 오른쪽 상단 닫기 아이콘을 클릭해서 폼 닫는 경우
- public static void CreateForm_FormClosing(object sender,FormClosingEventArgs e)
- {
- // 등록된 이벤트를 모두 삭제하고 등록된 폼 리스트에서 삭제한다
- Form CreateForm = (Form)sender;
- // 창이 소멸될때 잔상이 남는다
- CreateForm.Hide();
- // 이벤트1 : 해제
- _Event.FormClose_SendMessage_Event -= new _Event.FormClose_SendMessage_Handler(_Event_FormClose_SendMessage_Event);
- // 이벤트2 : 해제
- CreateForm.FormClosing -= new FormClosingEventHandler(CreateForm_FormClosing);
- // 리스트에서 삭제
- CreatedForm.Remove(CreateForm.Name);
- // 메인폼의 메뉴바에서 체크 해제
- if (CreateForm.Tag != null)
- {
- UICommand Command = (UICommand)CreateForm.Tag;
- Command.IsChecked = false;
- }
- // Log
- _Event.DebugView_SendMessage_Write(CreateForm.Name + _Text.Blank + _Text.LOG_CloseForm);
- }
- // 이벤트2 : 다른 폼에서 현재 생성된 폼을 닫기하라고 명령하는 경우
- public static void _Event_FormClose_SendMessage_Event(object sender, object etc)
- {
- // sender : null 이라면 모두 삭제, 폼이름 이라면 폼이름에 해당하는 폼만 삭제
- // etc : 사용미정
- // 모든 폼 삭제
- if (sender == null)
- {
- while (CreatedForm.Count != 0)
- {
- foreach (DictionaryEntry de in CreatedForm)
- {
- ((Form)de.Value).Close();
- break;
- }
- }
- }
- // 특정폼만 삭제
- else
- {
- Form senderForm = (Form)sender;
- foreach (DictionaryEntry de in CreatedForm)
- {
- if (senderForm.Name == de.Key.ToString())
- {
- senderForm.Close();
- break;
- }
- }
-
- }
- }
- }
- }
|