【问题标题】:How to get message over the text box如何通过文本框获取消息
【发布时间】:2017-01-13 04:58:41
【问题描述】:
我有一个带有命令列表的文本框界面,当用户将鼠标悬停在文本框上时,我想显示这个列表。
我可以放带有标签的消息,但似乎不是最好的方式,看起来不太好
这是我想要得到它的方式,并且与标签相同:
也许你可以给我一些更好的展示方式,也很有趣
【问题讨论】:
标签:
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);
}
结果: