SignaturePasswordForm.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace CLIP.eForm.Consent.UI
  5. {
  6. public partial class SignaturePasswordForm : Form
  7. {
  8. //선언
  9. private CLIP.eForm.UI.Parts.VirtualKeyboard.VirtualKeyboardForm _virKeyForm = null; //가상키보드
  10. private bool dualViewerState = false;
  11. public SignaturePasswordForm(string userName, string userId, bool dualViewer)
  12. {
  13. InitializeComponent();
  14. this.Text = string.Format("{0} - {1}", userName, userId);
  15. dualViewerState = dualViewer;
  16. // 이벤트 연결
  17. this.textBoxPassword.Click += new EventHandler(control_Click);
  18. }
  19. /// <summary>
  20. /// textBoxPassword 입력 컨트롤 클릭 이벤트 연결
  21. /// 듀얼 뷰어 상태가 아닐때 가상 키보드를 보여준다
  22. /// </summary>
  23. /// <param name="sender">The source of the event.</param>
  24. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  25. private void control_Click(object sender, EventArgs e)
  26. {
  27. if (!dualViewerState)
  28. {
  29. ShowVirtualKeyboard(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.CharKeyboard);
  30. Control control = sender as Control;
  31. control.Focus();
  32. }
  33. }
  34. /// <summary>
  35. /// 확인 버튼 클릭 이벤트
  36. /// 가상키보드를 숨기고 창을 닫는다
  37. /// </summary>
  38. /// <param name="sender">The source of the event.</param>
  39. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  40. private void btnOK_Click(object sender, EventArgs e)
  41. {
  42. if (!string.IsNullOrEmpty(this.textBoxPassword.Text))
  43. {
  44. HideVirtualKeyboard();
  45. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  46. }
  47. }
  48. /// <summary>
  49. /// 사용자가 입력한 패스워드 반환
  50. /// </summary>
  51. /// <returns>인증서 비밀번호 반환</returns>
  52. public string GetPassword()
  53. {
  54. return this.textBoxPassword.Text.ToString();
  55. }
  56. /// <summary>
  57. /// textBoxPassword 텍스트 박스 컨트롤 키보드 입력 이벤트
  58. /// </summary>
  59. /// <param name="sender">The source of the event.</param>
  60. /// <param name="e">The <see cref="KeyPressEventArgs"/> instance containing the event data.</param>
  61. private void textBoxPassword_KeyPress(object sender, KeyPressEventArgs e)
  62. {
  63. // 엔터키 입력 시 가상키보드를 숨기고 창을 닫는다
  64. if (e.KeyChar == (char)Keys.Return)
  65. {
  66. if (!string.IsNullOrEmpty(this.textBoxPassword.Text))
  67. {
  68. HideVirtualKeyboard();
  69. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  70. }
  71. }
  72. }
  73. /// <summary>
  74. /// 가상키보드 보이기
  75. /// </summary>
  76. /// <param name="keyboardType">키보드 타입</param>
  77. private void ShowVirtualKeyboard(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType keyboardType)
  78. {
  79. HideVirtualKeyboard();
  80. if (_virKeyForm == null)
  81. {
  82. _virKeyForm = new CLIP.eForm.UI.Parts.VirtualKeyboard.VirtualKeyboardForm(CLIP.eForm.UI.Parts.VirtualKeyboard.IME.korean, keyboardType, true);
  83. _virKeyForm.OnKeyPressEvent += new KeyEventHandler(_virKeyForm_OnKeyPressEvent); //Key-Down Event
  84. _virKeyForm.OnClickCustomExitButton += new EventHandler(_virKeyForm_OnClickCustomExitButton); //가상키보드 종료이벤트
  85. _virKeyForm.StartPosition = FormStartPosition.Manual;
  86. }
  87. //Set Location
  88. _virKeyForm.Bounds = GetVirtualKeyboardLocation(keyboardType);
  89. _virKeyForm.Show();
  90. }
  91. /// <summary>
  92. /// Key-Down 이벤트 연결 주로
  93. /// 특정키의 입력에 대해 처리하는경우, 사용한다.
  94. /// </summary>
  95. /// <param name="sender">Sender</param>
  96. /// <param name="e">Key Info</param>
  97. private void _virKeyForm_OnKeyPressEvent(object sender, KeyEventArgs e)
  98. {
  99. //// 사용예제
  100. //if (e.KeyData == Keys.Enter || e.KeyData == Keys.Escape)
  101. //{
  102. // //특정로직 처리
  103. // HideVirtualKeyboard();
  104. //}
  105. }
  106. /// <summary>
  107. /// 가상키보드 위치잡기
  108. /// 프로그램이 위치한 스크린 하단의 Location을 반환한다.
  109. /// </summary>
  110. /// <param name="keyboardType">키보드 타입</param>
  111. /// <returns></returns>
  112. private Rectangle GetVirtualKeyboardLocation(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType keyboardType)
  113. {
  114. int x = 0;
  115. int bottom = 0;
  116. int width = 0;
  117. int minusTitleBarHeight = SystemInformation.ToolWindowCaptionHeight + SystemInformation.FrameBorderSize.Height;
  118. Rectangle screenLocation = GetScreenPosition();
  119. if (keyboardType == CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.CharKeyboard)
  120. {
  121. x = screenLocation.X;
  122. width = screenLocation.Width;
  123. }
  124. else if (keyboardType == CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.NumPad)
  125. {
  126. x = screenLocation.X + screenLocation.Width - _virKeyForm.Width;
  127. width = (int)(screenLocation.Width / 3.0f);
  128. }
  129. bottom = screenLocation.Height - _virKeyForm.Height - minusTitleBarHeight;
  130. return new Rectangle(x, bottom, width, _virKeyForm.Height);
  131. }
  132. /// <summary>
  133. /// 현재 프로그램이 위치한 스크린의 Bound정보를 반환한다.
  134. /// </summary>
  135. /// <returns></returns>
  136. private Rectangle GetScreenPosition()
  137. {
  138. Screen[] dualScreen = Screen.AllScreens;
  139. Rectangle screenBound = Rectangle.Empty;
  140. foreach (Screen sc in dualScreen)
  141. {
  142. if (sc.Bounds.Contains(this.Location) == true)
  143. {
  144. screenBound = sc.WorkingArea;
  145. break;
  146. }
  147. }
  148. return screenBound;
  149. }
  150. //가상키보드 숨기기
  151. private void HideVirtualKeyboard()
  152. {
  153. if (_virKeyForm != null)
  154. {
  155. _virKeyForm.Close();
  156. _virKeyForm = null;
  157. }
  158. }
  159. //가상키보드 종료버튼 함수
  160. private void _virKeyForm_OnClickCustomExitButton(object sender, EventArgs e)
  161. {
  162. HideVirtualKeyboard();
  163. }
  164. private void SignaturePasswordForm_Load(object sender, EventArgs e)
  165. {
  166. if(!dualViewerState)
  167. {
  168. ShowVirtualKeyboard(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.CharKeyboard);
  169. this.textBoxPassword.Focus();
  170. }
  171. }
  172. protected override void OnActivated(EventArgs e)
  173. {
  174. this.textBoxPassword.Focus();
  175. base.OnActivated(e);
  176. }
  177. private void SignaturePasswordForm_FormClosed(object sender, FormClosedEventArgs e)
  178. {
  179. HideVirtualKeyboard();
  180. }
  181. private void tabpointButton1_Click(object sender, EventArgs e)
  182. {
  183. HideVirtualKeyboard();
  184. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  185. }
  186. }
  187. }