Search code examples
c#winformstextboxmessage

How to get message over the text box


I have interface with textbox which has list of commands, and I want to show this list when the user hover the mouse on textbox.

I can put message with label, but seems it is not the best way, looks not really good

Here is how I want get it and and same with labels:

enter image description here

Maybe you can advice me some better way to show it, also very interesting


Solution

  • As Reza Aghaei had already said to use a ToolTip. Here's how you can do it:

    Creating and returning the list:

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

    Displaying the Tooltip on the Enter event of the TextBox:

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

    Result:

    tooltip