TextBoxWithTextArea.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using UAS_MES.PublicMethod;
  5. namespace UAS_MES.CustomControl.TextBoxWithIcon
  6. {
  7. public partial class TextBoxWithTextArea : UserControl
  8. {
  9. public TextBoxWithTextArea()
  10. {
  11. InitializeComponent();
  12. }
  13. //重写Text方法,用于接收或者传递值
  14. public override string Text
  15. {
  16. get
  17. {
  18. return textBox1.Text;
  19. }
  20. set
  21. {
  22. textBox1.Text = value;
  23. }
  24. }
  25. private void TextAreaIcon_Click(object sender, EventArgs e)
  26. {
  27. //获取相对屏幕左上角的位置的坐标,传给TextAreaForm作为初始化的坐标
  28. var screenPoint = PointToScreen(TextAreaIcon.Location);
  29. bool GetParent = true;
  30. TextAreaForm taf = new TextAreaForm();
  31. //需要传递当前的Form名称,控件名称,和相对屏幕的位置
  32. string FormName = this.FindForm().Name;
  33. int i = 0;
  34. //当前的this是控件的Icon
  35. Control c=this;
  36. //一直通过父级往上找,直到父级的名称和Form的名称相等,记录经过了多少级
  37. while (GetParent)
  38. {
  39. c= c.Parent;
  40. if (c.Name == FormName)
  41. {
  42. GetParent = false;
  43. }
  44. i++;
  45. }
  46. //指定一个数据用来存放查找过的Control的Name
  47. string[] ControlsName=new string[i];
  48. //指定Form的名称
  49. taf.FormName = FormName;
  50. //重置Icon
  51. c = this;
  52. //将控件的名称添加到字符串数组中
  53. for (int j = 0; j < i; j++) {
  54. if (c.Name != FormName)
  55. {
  56. ControlsName[j] = c.Name;
  57. }
  58. c = c.Parent;
  59. }
  60. taf.ControlName = ControlsName;
  61. BaseUtil.SetFormCenter(taf);
  62. taf.ShowDialog();
  63. }
  64. private void textBox1_Leave(object sender, EventArgs e)
  65. {
  66. textBox1.BackColor = Color.White;
  67. }
  68. private void textBox1_Enter(object sender, EventArgs e)
  69. {
  70. textBox1.BackColor = Color.GreenYellow;
  71. }
  72. }
  73. }