1b64be4ebe56b628e3512bb673590ab15293190f.svn-base 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7. using System.Collections;
  8. using Janus.Windows.UI.CommandBars;
  9. namespace IControls_FireManager
  10. {
  11. // 폼생성에 관련된 함수는 여기 클래스에서 전담한다
  12. public static class _Form
  13. {
  14. // 중복 생성 방지용 해쉬테이블 (폼이름, 폼)
  15. public static Hashtable CreatedForm = new Hashtable();
  16. // 폼 생성하기
  17. // 폼을 닫는 이벤트는 2가지이다
  18. // 이벤트1 : 생성된 폼에서 오른쪽 상단 닫기 아이콘을 클릭해서 폼 닫는 경우 -> CreateForm.FormClosing
  19. // 이벤트2 : 다른 폼에서 현재 생성된 폼을 닫기하라고 명령하는 경우 -> _Event.FormClose_SendMessage_Event
  20. // UIcommand 메뉴바 체크 상태 구현 : UICommand 가 null 이면 메뉴바에서 생성된 폼이 아닌것으로 간주함
  21. public static void Create(Form CreateForm, UICommand UIcommand)
  22. {
  23. // 폼이름을 키로 함. 결국 폼이름으로 검색
  24. if (CreatedForm.Contains(CreateForm.Name) == true)
  25. {
  26. // 이미 생성된 폼이라면 포커스를 준다
  27. // 파라미터는 동적생성한 폼이므로 파라미터의 속성을 접근해서는 안된다.
  28. foreach (DictionaryEntry de in CreatedForm)
  29. {
  30. if (CreateForm.Name == de.Key.ToString())
  31. {
  32. // 최대화 혹은 최소화 된 창을 일반으로 돌리고 포커스를 줌
  33. ((Form)de.Value).WindowState = FormWindowState.Normal;
  34. ((Form)de.Value).Focus();
  35. break;
  36. }
  37. }
  38. }
  39. else
  40. {
  41. // 폼이름(Form 속성의 Name 이 Key 값이다. 리스트에 추가함
  42. CreatedForm.Add(CreateForm.Name,CreateForm);
  43. // 이벤트1 : 생성된 폼에서 오른쪽 상단 닫기 아이콘을 클릭해서 폼 닫는 경우
  44. _Event.FormClose_SendMessage_Event +=new _Event.FormClose_SendMessage_Handler(_Event_FormClose_SendMessage_Event);
  45. // 이벤트2 : 다른 폼에서 현재 생성된 폼을 닫기하라고 명령하는 경우
  46. CreateForm.FormClosing +=new FormClosingEventHandler(CreateForm_FormClosing);
  47. // 새창 출력시 맨앞으로 보이게함
  48. //debug CreateForm.TopMost = true;
  49. // 보이기
  50. CreateForm.Show();
  51. // 옵션 (추가하고 싶은 옵션은 여기에서 처리)
  52. CreateForm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  53. // 메인폼의 메뉴바에서 체크 표시
  54. if (UIcommand != null )
  55. {
  56. UIcommand.IsChecked = true;
  57. CreateForm.Tag = UIcommand;
  58. }
  59. // Log
  60. _Event.DebugView_SendMessage_Write(CreateForm.Name + _Text.Blank + _Text.LOG_CreateForm);
  61. }
  62. }
  63. // 이벤트1 : 생성된 폼에서 오른쪽 상단 닫기 아이콘을 클릭해서 폼 닫는 경우
  64. public static void CreateForm_FormClosing(object sender,FormClosingEventArgs e)
  65. {
  66. // 등록된 이벤트를 모두 삭제하고 등록된 폼 리스트에서 삭제한다
  67. Form CreateForm = (Form)sender;
  68. // 창이 소멸될때 잔상이 남는다
  69. CreateForm.Hide();
  70. // 이벤트1 : 해제
  71. _Event.FormClose_SendMessage_Event -= new _Event.FormClose_SendMessage_Handler(_Event_FormClose_SendMessage_Event);
  72. // 이벤트2 : 해제
  73. CreateForm.FormClosing -= new FormClosingEventHandler(CreateForm_FormClosing);
  74. // 리스트에서 삭제
  75. CreatedForm.Remove(CreateForm.Name);
  76. // 메인폼의 메뉴바에서 체크 해제
  77. if (CreateForm.Tag != null)
  78. {
  79. UICommand Command = (UICommand)CreateForm.Tag;
  80. Command.IsChecked = false;
  81. }
  82. // Log
  83. _Event.DebugView_SendMessage_Write(CreateForm.Name + _Text.Blank + _Text.LOG_CloseForm);
  84. }
  85. // 이벤트2 : 다른 폼에서 현재 생성된 폼을 닫기하라고 명령하는 경우
  86. public static void _Event_FormClose_SendMessage_Event(object sender, object etc)
  87. {
  88. // sender : null 이라면 모두 삭제, 폼이름 이라면 폼이름에 해당하는 폼만 삭제
  89. // etc : 사용미정
  90. // 모든 폼 삭제
  91. if (sender == null)
  92. {
  93. while (CreatedForm.Count != 0)
  94. {
  95. foreach (DictionaryEntry de in CreatedForm)
  96. {
  97. ((Form)de.Value).Close();
  98. break;
  99. }
  100. }
  101. }
  102. // 특정폼만 삭제
  103. else
  104. {
  105. Form senderForm = (Form)sender;
  106. foreach (DictionaryEntry de in CreatedForm)
  107. {
  108. if (senderForm.Name == de.Key.ToString())
  109. {
  110. senderForm.Close();
  111. break;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }