123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace UAS_MES_NEW.CustomControl.TextBoxWithIcon
- {
- public partial class TextBoxWithTextArea : UserControl
- {
- bool TextBoxEnable1;
- bool TextAreaEnable1;
- public TextBoxWithTextArea()
- {
- InitializeComponent();
- }
- //重写Text方法,用于接收或者传递值
- public override string Text
- {
- get
- {
- return TextAreaTextBox.Text;
- }
- set
- {
- TextAreaTextBox.Text = value;
- }
- }
- public bool TextBoxEnable
- {
- get
- {
- return TextBoxEnable1;
- }
- set
- {
- TextBoxEnable1 = value;
- }
- }
- public bool TextAreaEnable
- {
- get
- {
- return TextAreaEnable1;
- }
- set
- {
- TextAreaEnable1 = value;
- }
- }
- private void TextAreaIcon_Click(object sender, EventArgs e)
- {
- //获取相对屏幕左上角的位置的坐标,传给TextAreaForm作为初始化的坐标
- var screenPoint = PointToScreen(TextAreaIcon.Location);
- bool GetParent = true;
- TextAreaForm taf = new TextAreaForm();
- taf.Controls["TextArea"].Enabled = TextAreaEnable1;
- taf.Controls["Clean"].Enabled = TextAreaEnable1;
- //需要传递当前的Form名称,控件名称,和相对屏幕的位置
- string FormName = this.FindForm().Name;
- int i = 0;
- //当前的this是控件的Icon
- Control c = this;
- //一直通过父级往上找,直到父级的名称和Form的名称相等,记录经过了多少级
- while (GetParent)
- {
- c = c.Parent;
- if (c.Name == FormName)
- {
- GetParent = false;
- }
- i++;
- }
- //指定一个数据用来存放查找过的Control的Name
- string[] ControlsName = new string[i];
- //指定Form的名称
- taf.FormName = FormName;
- //重置Icon
- c = this;
- //将控件的名称添加到字符串数组中
- for (int j = 0; j < i; j++)
- {
- if (c.Name != FormName)
- {
- ControlsName[j] = c.Name;
- }
- c = c.Parent;
- }
- taf.ControlName = ControlsName;
- taf.X = screenPoint.X / 2;
- taf.Y = screenPoint.Y / 2;
- taf.ShowDialog();
- }
- private void textBox1_Leave(object sender, EventArgs e)
- {
- TextAreaTextBox.BackColor = Color.White;
- }
- private void textBox1_Enter(object sender, EventArgs e)
- {
- TextAreaTextBox.BackColor = Color.GreenYellow;
- }
- private void TextBoxWithTextArea_SizeChanged(object sender, EventArgs e)
- {
- TextAreaTextBox.Width = this.Width - TextAreaIcon.Width - 3;
- }
- private void TextBoxWithTextArea_Load(object sender, EventArgs e)
- {
- TextAreaTextBox.Enabled = TextBoxEnable1;
- }
- }
- }
|