Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言显示一个文本弹出窗口#_C#_Winforms - Fatal编程技术网

C# 用C语言显示一个文本弹出窗口#

C# 用C语言显示一个文本弹出窗口#,c#,winforms,C#,Winforms,在一个表单中,我有一个标签,但标签文本超出了面板边界,当鼠标在标签上停留一段时间后显示一个包含所有文本的弹出窗口时,我该怎么办 编辑:这里是代码: public partial class AppMenuItem : UserControl { public string path; public string name { get { return label1.Text; } } public AppMenuItem(string

在一个表单中,我有一个标签,但标签文本超出了面板边界,当鼠标在标签上停留一段时间后显示一个包含所有文本的弹出窗口时,我该怎么办

编辑:这里是代码:

public partial class AppMenuItem : UserControl
{
    public string path;

    public string name
    {
        get { return label1.Text; }
    }

    public AppMenuItem(string path, string name)
    {
        InitializeComponent();
        label1.Text = name;
        this.path = path;
        pictureBox1.Image = ShortcutsHelper.GetIcon(path);
    }

    private void pinToStartToolStripMenuItem_Click(object sender, EventArgs e)
    {
        TilesHelper.AddTile(this.name, this.path);
    }

    private void label1_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            contextMenuStrip1.Show(this.PointToScreen(Point.Empty));
        }
        else
        {
            System.Diagnostics.Process.Start(path);
            ((AppForm)this.ParentForm).DialogResult = DialogResult.OK;
            ((AppForm)this.ParentForm).Close();
            ((AppForm)this.ParentForm).textBox1.Text = "";
        }
    }

    private void label1_MouseHover(object sender, EventArgs e)
    {
        new ToolTip().Show(this.name, this.ParentForm);
    }
}
您正在尝试添加一个

编辑:您应该删除
MouseHover
事件,并向构造函数中的标签添加工具提示:

public AppMenuItem(string path, string name)
{
    InitializeComponent();
    label1.Text = name;
    this.path = path;
    pictureBox1.Image = ShortcutsHelper.GetIcon(path);
    ToolTip tt = ToolTip();
    tt.SetToolTip(label1, name);
}
您必须创建一个对象并设置所需的文本:

System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
    ToolTip1.SetToolTip(this.Label1, this.Label1.Text);

查看MSDN:

非常感谢大家!效验如神等待如何在鼠标光标处显示弹出窗口,并且只允许一个弹出窗口?@GiulioZausa Windows应注意在用户将光标移离标签后关闭工具提示。由于只有一个鼠标指针,用户一次不能激活多个工具提示弹出窗口。这不是你看到的吗?@GiulioZausa这很奇怪。你能用你用来创建工具提示的代码更新这个问题吗?@GiulioZausa请查看编辑。工具提示应自动检测鼠标悬停事件,并在用户将鼠标指针移到标签上时显示/取消显示。
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
    ToolTip1.SetToolTip(this.Label1, this.Label1.Text);