locked
ToolTip, not ToolTip ? RRS feed

  • Question

  • Hello,

    Very often when you browse the web you run into a textBox with something that appears like a ToolTip inside. Frequently this text inside is kind of dimmed, you put a cursor in the window and the text disappears. It may say something line: "Your email," or have already your zip code as a prompt.

    I want to reproduce it in my coding but both tooltips don't give similar effect. I also checked all properties for the TextBox in C# ToolBox and could not find anything. It can probably reproduced programmatically but I wonder about a special property.

    Can it be done in MSVS?

    Thanks, - MyCatAlex


    • Edited by MyCatAlex Saturday, July 28, 2018 3:10 PM
    Saturday, July 28, 2018 3:03 PM

All replies

  • In Win32 Edit controls, it is done with EM_SETCUEBANNER
    Saturday, July 28, 2018 3:25 PM
  • There is nothing in the C# language that will do that, you need to use a GUI such as WPF or Windows Forms to do that. So this question should not be in the C# language forum.

    You can probably draw the text using graphics, as in How to: Draw Text on a Windows Form. However that sample is misleading; see the part that says "you should override the OnPaint method". That makes it more complicated. See Graphics and Drawing in Windows Forms for a description of graphics in Windows; I am sure you don't want to have to read all of that but it is relevant to most all uses of graphics in Windows.

    If you are using WPF and not Windows Forms then you should have said that.



    Sam Hobbs
    SimpleSamples.Info

    Saturday, July 28, 2018 3:49 PM
  • I think it is bad think. There is "Your email" text in text box. I click into textbox, text dissapeares, someone calls to to me for 5 minute I go back to page and I need to ask what I need to fill into this textbox? :)
    Monday, July 30, 2018 3:18 AM
  • Hi MyCatAlex,

    Thank you for posting here.

    For your question, here is a simple code of tooltip for your reference.

      private void TextBox1_MouseMove(object sender, MouseEventArgs e)
            {
                TextBox TB = (TextBox)sender;
                int VisibleTime = 1000;  //in milliseconds
    
                ToolTip tt = new ToolTip();
                tt.Show("Your email", TB, 0, 0, VisibleTime);
                textBox1.Visible = false;
            }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 30, 2018 8:37 AM