在文本框条目上显示工具提示

Show tooltip on textbox entry(在文本框条目上显示工具提示)

本文介绍了在文本框条目上显示工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 textbox 需要以某种方式输入数据.我已经实现了一些单元格验证技术来在输入数据后检查数据,但我想在用户输入数据之前向他们提供一些信息.

I have a textbox that requires data to be entered in a certain way. I have implemented some cell validating techniques to check the data after it has been entered, but I'd like to provide the user with some information before they enter the data.

为此,我想在textbox 中添加一个tooltip,当用户进入工具箱时弹出该tooltip,然后在他们开始输入时退出.

To that end, I'd like to add a tooltip to the textbox that pops up when the user enters the toolbox, then exits when they begin to type.

例如我有以下代码:

private void YearEdit_Enter(object sender, EventArgs e)
  {
        ToolTip tt = new ToolTip();
        tt.IsBalloon = true;
        tt.InitialDelay = 0;
        tt.ShowAlways = true;
        tt.SetToolTip(YearEdit, "Enter 4 digit year.");
    }

这在用户输入 textbox 时执行,但是 tooltip 仅在鼠标悬停在 textbox 上时出现.有没有人有任何想法来解决这个问题?我认为也许 tt.ShowAlways = true 可能有效,但显然不是.

This executes when the user enters the textbox, however the tooltip only appears when the mouse hovers over the textbox. Does anyone have any ideas to work around this? I thought that perhaps tt.ShowAlways = true might work, but obviously not.

推荐答案

挂钩到 textbox.enter 事件并使用以下代码:

Hook into the textbox.enter event and use the following code:

private void textBox1_Enter(object sender, EventArgs e)
    {
        TextBox TB = (TextBox)sender;
        int VisibleTime = 1000;  //in milliseconds

        ToolTip tt = new ToolTip();
        tt.Show("Test ToolTip",TB,0,0,VisibleTime);
    }

使用 X/Y 值将其移动到您想要的位置.可见时间是它消失的时间.

Play with X/Y values to move it where you want. Visible time is how long until it disappears.

这篇关于在文本框条目上显示工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在文本框条目上显示工具提示

基础教程推荐