【问题标题】:How to get message over the text box如何通过文本框获取消息
【发布时间】:2017-01-13 04:58:41
【问题描述】:

我有一个带有命令列表的文本框界面,当用户将鼠标悬停在文本框上时,我想显示这个列表。

我可以放带有标签的消息,但似乎不是最好的方式,看起来不太好

这是我想要得到它的方式,并且与标签相同:

也许你可以给我一些更好的展示方式,也很有趣

【问题讨论】:

  • 您可以使用ToolTip
  • @Reza Aghaei 所以这就是我猜的答案
  • 是的,这就是答案:)

标签: c# winforms textbox messages


【解决方案1】:

正如Reza Aghaei 已经说过要使用ToolTip。你可以这样做:

创建并返回列表:

static List<string> PopulateList()
{
    List<string> mylist = new List<string>();
    mylist.Add("insert (a1) to get this");
    mylist.Add("insert (a2) to get this");
    mylist.Add("insert (a3) to get this");
    mylist.Add("insert (a4) to get this");
    ...
    ...
    return mylist;
}

在TextBox的Enter事件上显示Tooltip:

private void textBox1_Enter(object sender, EventArgs e)
{
    string tooltiptext = "";
    List<string> mylist = PopulateList();
    foreach (string listitem in mylist)
    {
        tooltiptext += listitem + "\n";
    }
    ToolTip tt = new ToolTip();
    tt.Show(tooltiptext, textBox1, 2000);
}

结果:

【讨论】:

猜你喜欢
  • 2020-05-04
  • 1970-01-01
  • 1970-01-01
  • 2016-10-13
  • 2017-12-08
  • 2020-08-19
  • 2013-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多