我需要在文本框中显示一系列带有一些特殊符号的数字,当鼠标悬停在它们上方时可以显示更多信息。
例如,我在 TextBox 中放入如下内容:
Value: 45*, 35,21 21,34
当用户将鼠标移到“*”符号上时,会出现一个小窗口,其中包含一些文本。
这可能吗?我有点困惑如何做到这一点...事实上,文本中的超链接之类的东西可能也有帮助..
最佳答案
您可以使用 GetCharFromPosition 函数来确定鼠标位于哪个字符上:
ToolTip tt = new ToolTip();
Char lastChar = ' ';
void textBox1_MouseMove(object sender, MouseEventArgs e) {
char c = textBox1.GetCharFromPosition(e.Location);
if (c.Equals('*')) {
if (!c.Equals(lastChar)) {
lastChar = c;
tt.Show("This is something special", this.textBox1,
new Point(e.Location.X + 20, e.Location.Y + 20),
2000);
}
} else {
lastChar = ' ';
tt.Hide(this.textBox1);
}
}
关于c# - 如何检测TextBox中的特殊符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21856267/