2

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

编辑:这里的代码:

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);
    }
}
4

3 回答 3

2

您是否尝试添加ToolTip

var fullText = "quick brown fox jumps over the lazy dog";
System.Windows.Forms.ToolTip tt = new System.Windows.Forms.ToolTip();
tt.SetToolTip(this.label1, fullText);

编辑:您应该删除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);
}
于 2012-05-07T15:00:40.653 回答
2

您必须创建一个ToolTIp对象并设置所需的文本:

System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
    ToolTip1.SetToolTip(this.Label1, this.Label1.Text);
于 2012-05-07T15:01:04.560 回答
1

检查 MSDN:http: //msdn.microsoft.com/en-us/library/system.windows.forms.label.autoellipsis.aspx

于 2012-05-07T15:05:25.310 回答