F_SYS_0104.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace Dongke.IBOSS.PRD.Client.Public
  5. {
  6. public partial class F_SYS_0104 : Form
  7. {
  8. private const int WS_EX_TOOLWINDOW = 0x00000080;
  9. private const int WS_EX_NOACTIVATE = 0x08000000;
  10. protected override CreateParams CreateParams
  11. {
  12. get
  13. {
  14. CreateParams cp = base.CreateParams;
  15. cp.ExStyle |= (WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW);
  16. cp.Parent = IntPtr.Zero; // Keep this line only if you used UserControl
  17. return cp;
  18. //return base.CreateParams;
  19. }
  20. }
  21. private TextBox _textbox = null;
  22. public F_SYS_0104()
  23. {
  24. InitializeComponent();
  25. }
  26. public void SetLocation(TextBox textbox)
  27. {
  28. this._textbox = textbox;
  29. Point p = this.GetLocation(textbox);
  30. p.Offset(12, textbox.Height + 12);
  31. this.Location = p;
  32. }
  33. private void btnClose_Click(object sender, EventArgs e)
  34. {
  35. Button b = sender as Button;
  36. if(b == null)
  37. {
  38. return ;
  39. }
  40. string text = this._textbox.Text;
  41. switch (b.Text)
  42. {
  43. case "关闭":
  44. this.Close();
  45. break;
  46. case "<-":
  47. System.Windows.Forms.SendKeys.Send("{BACKSPACE}");
  48. break;
  49. case "Delete":
  50. System.Windows.Forms.SendKeys.Send("{DELETE}");
  51. break;
  52. default:
  53. System.Windows.Forms.SendKeys.Send(b.Text);
  54. break;
  55. }
  56. }
  57. private Point GetLocation(Control c)
  58. {
  59. if (c.Parent == null)
  60. {
  61. return c.Location;
  62. }
  63. if (c.Parent is Form)
  64. {
  65. Point p = c.Parent.Location;
  66. p.Offset(c.Location);
  67. return p;
  68. }
  69. Point pc = this.GetLocation(c.Parent);
  70. pc.Offset(c.Location);
  71. return pc;
  72. }
  73. }
  74. }