如何在鼠标移动到TEXTFIELD上显示一窗口
问题:当鼠标移动到该区域,我怎么获取鼠标所在位置的TEXTFIELD 回复 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;
}
谢谢:) 回复 3楼zjl880的帖子
:share:
页:
[1]