SignaturePasswordForm.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace CLIP.eForm.Consent.Dfh.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. //이벤트 함수
  20. private void control_Click(object sender, EventArgs e)
  21. {
  22. if (!dualViewerState)
  23. {
  24. ShowVirtualKeyboard(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.CharKeyboard);
  25. Control control = sender as Control;
  26. control.Focus();
  27. }
  28. }
  29. private void btnOK_Click(object sender, EventArgs e)
  30. {
  31. if (!string.IsNullOrEmpty(this.textBoxPassword.Text))
  32. {
  33. HideVirtualKeyboard();
  34. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  35. }
  36. }
  37. public string GetPassword()
  38. {
  39. return this.textBoxPassword.Text.ToString();
  40. }
  41. private void textBoxPassword_KeyPress(object sender, KeyPressEventArgs e)
  42. {
  43. if (e.KeyChar == (char)Keys.Return)
  44. {
  45. if (!string.IsNullOrEmpty(this.textBoxPassword.Text))
  46. {
  47. HideVirtualKeyboard();
  48. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  49. }
  50. }
  51. }
  52. //가상키보드 보이기
  53. private void ShowVirtualKeyboard(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType keyboardType)
  54. {
  55. HideVirtualKeyboard();
  56. if (_virKeyForm == null)
  57. {
  58. _virKeyForm = new CLIP.eForm.UI.Parts.VirtualKeyboard.VirtualKeyboardForm(CLIP.eForm.UI.Parts.VirtualKeyboard.IME.korean, keyboardType);
  59. _virKeyForm.OnKeyPressEvent += new KeyEventHandler(_virKeyForm_OnKeyPressEvent); //Key-Down Event
  60. _virKeyForm.OnClickCustomExitButton += new EventHandler(_virKeyForm_OnClickCustomExitButton); //가상키보드 종료이벤트
  61. _virKeyForm.StartPosition = FormStartPosition.Manual;
  62. }
  63. //Set Location
  64. _virKeyForm.Bounds = GetVirtualKeyboardLocation(keyboardType);
  65. _virKeyForm.Show();
  66. }
  67. //Key-Down 이벤트 연결
  68. /// <summary>
  69. /// Key-Down Event. 주로, 특정키의 입력에 대해 처리하는경우, 사용한다.
  70. /// </summary>
  71. /// <param name="sender">Sender</param>
  72. /// <param name="e">Key Info</param>
  73. private void _virKeyForm_OnKeyPressEvent(object sender, KeyEventArgs e)
  74. {
  75. //// 사용예제
  76. //if (e.KeyData == Keys.Enter || e.KeyData == Keys.Escape)
  77. //{
  78. // //특정로직 처리
  79. // HideVirtualKeyboard();
  80. //}
  81. }
  82. //가상키보드 위치잡기
  83. /// <summary>
  84. /// 프로그램이 위치한 스크린 하단의 Location을 반환한다.
  85. /// </summary>
  86. /// <param name="keyboardType">키보드 타입</param>
  87. /// <returns></returns>
  88. private Rectangle GetVirtualKeyboardLocation(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType keyboardType)
  89. {
  90. int x = 0;
  91. int bottom = 0;
  92. int width = 0;
  93. int minusTitleBarHeight = SystemInformation.ToolWindowCaptionHeight + SystemInformation.FrameBorderSize.Height;
  94. Rectangle screenLocation = GetScreenPosition();
  95. if (keyboardType == CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.CharKeyboard)
  96. {
  97. x = screenLocation.X;
  98. width = screenLocation.Width;
  99. }
  100. else if (keyboardType == CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.NumPad)
  101. {
  102. x = screenLocation.X + screenLocation.Width - _virKeyForm.Width;
  103. width = (int)(screenLocation.Width / 3.0f);
  104. }
  105. bottom = screenLocation.Height - _virKeyForm.Height - minusTitleBarHeight;
  106. return new Rectangle(x, bottom, width, _virKeyForm.Height);
  107. }
  108. /// <summary>
  109. /// 현재 프로그램이 위치한 스크린의 Bound정보를 반환한다.
  110. /// </summary>
  111. /// <returns></returns>
  112. private Rectangle GetScreenPosition()
  113. {
  114. Screen[] dualScreen = Screen.AllScreens;
  115. Rectangle screenBound = Rectangle.Empty;
  116. foreach (Screen sc in dualScreen)
  117. {
  118. if (sc.Bounds.Contains(this.Location) == true)
  119. {
  120. screenBound = sc.WorkingArea;
  121. break;
  122. }
  123. }
  124. return screenBound;
  125. }
  126. //가상키보드 숨기기
  127. private void HideVirtualKeyboard()
  128. {
  129. if (_virKeyForm != null)
  130. {
  131. _virKeyForm.Close();
  132. _virKeyForm = null;
  133. }
  134. }
  135. //가상키보드 종료버튼 함수
  136. private void _virKeyForm_OnClickCustomExitButton(object sender, EventArgs e)
  137. {
  138. HideVirtualKeyboard();
  139. }
  140. private void SignaturePasswordForm_Load(object sender, EventArgs e)
  141. {
  142. if(!dualViewerState)
  143. {
  144. ShowVirtualKeyboard(CLIP.eForm.UI.Parts.VirtualKeyboard.KeyboardType.CharKeyboard);
  145. this.textBoxPassword.Focus();
  146. }
  147. }
  148. protected override void OnActivated(EventArgs e)
  149. {
  150. this.textBoxPassword.Focus();
  151. base.OnActivated(e);
  152. }
  153. private void SignaturePasswordForm_FormClosed(object sender, FormClosedEventArgs e)
  154. {
  155. HideVirtualKeyboard();
  156. }
  157. private void tabpointButton1_Click(object sender, EventArgs e)
  158. {
  159. HideVirtualKeyboard();
  160. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  161. }
  162. }
  163. }