c# - 如何检测TextBox中的特殊符号?

标签 c# winforms

我需要在文本框中显示一系列带有一些特殊符号的数字,当鼠标悬停在它们上方时可以显示更多信息。

例如,我在 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/

相关文章:

c# - 运算符 '>' 无法使用 Asp.net Mvc 应用于类型 'string' 和 'int' 的操作数

c# - c#调用窗体后如何返回调用方法?

c# - SQL 更新 - 不更新 for 循环中的多行

.net - Visual Studio 设计器表单中 ToolStrip 的自定义 ToolStripButton

c# - 单窗口窗体中的从右到左文本

c# - 在c#中检查线程是否正在运行

c# - 如何设置几个visual C#项目的输出路径

c# - LINQ 到实体 : How to return the latest order number for a customer

c# - 动态加载具有相同功能的不同库

c# - C#从DataGridView中读取数据