回复 1楼zjl880的帖子
获取方法请参考代码:
- private void Form1_Load(object sender, EventArgs e)
- {
- TXTextControl.TextField field = new TXTextControl.TextField();
- field.Text = "位置测试";
- field.ID = 10;
- this.textControl1.TextFields.Add(field);
- this.textControl1.MouseMove += new MouseEventHandler(textControl1_MouseMove);
- }
- void textControl1_MouseMove(object sender, MouseEventArgs e)
- {
- TXTextControl.TextField field = GetTextFieldFromLocation(e.Location);
- if (field!=null)
- {
- MessageBox.Show(field.Text);
- }
- }
- private TXTextControl.TextField GetTextFieldFromLocation(Point Location)
- {
- Graphics g = textControl1.CreateGraphics();
- int iDpi = (int)(1440 / g.DpiX);
- Point pTwipsLocation = new Point(Location.X * iDpi, Location.Y * iDpi);
- foreach (TXTextControl.TextField tfField in textControl1.TextFields)
- {
- Rectangle rFieldBounds = new Rectangle(tfField.Bounds.X - textControl1.ScrollLocation.X,
- tfField.Bounds.Y - textControl1.ScrollLocation.Y, tfField.Bounds.Width,
- tfField.Bounds.Height);
- if (pTwipsLocation.X >= rFieldBounds.X && pTwipsLocation.X <= rFieldBounds.X
- + rFieldBounds.Width && pTwipsLocation.Y >=
- rFieldBounds.Y && pTwipsLocation.Y <= rFieldBounds.Y + rFieldBounds.Height)
- {
- return tfField;
- }
- }
- return null;
- }
复制代码 |