locked
placeholder in c# RRS feed

  • Question

  • hi 

    i want to show user some thing message what value we entered in Text box using place holder in c# 

    • Moved by CoolDadTx Tuesday, August 16, 2016 9:06 PM Winforms related
    Tuesday, August 16, 2016 2:20 PM

Answers

  • You could try using the below code. Hope this helps you.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace PlaceHolderTbox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void textBox1_Enter(object sender, EventArgs e)
            {
                if(textBox1.Text=="Enter some text here")
                {
                    textBox1.Text = "";
                }
            }
    
            private void textBox1_Leave(object sender, EventArgs e)
            {
                if (textBox1.Text == "")
                {
                    textBox1.Text = "Enter some text here";
                    textBox1.ForeColor = Color.Gray;
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.Text = "Enter some text here";
            }
        }
    }

    pls marks as answer if your query is resolve.


    Tuesday, August 16, 2016 2:30 PM
  • Requirements are not clear.

    String.Format does support placeholders to be put into the string. It is used extensively by Console.WriteLine().
    Of course basic string conaction (+ operator) or StringBuilder can also work.

    Also ToString() and Convert functions can be modified heavily via parameters, if you need specific output formats (specific Culture, Number Format, base of the output).

    If this is about internationalisation - there is no easy answer here. Timezones are madness inducing bad. That is even worse:
    https://www.youtube.com/watch?v=0j74jcxSunY

    Tuesday, August 16, 2016 5:39 PM
  • Hi Sanjay,

    I guess we are having a hard time understanding your requirements. Is this for a homework assignment?

    If not can you tell us a line or two about the business scenario you are trying to resolve?

    Here are a couple of possible answers for you:

    1 - You want the user to enter text in a textbox, then you want the content of that textbox to be displayed to the user.

    If this is the case, use a textbox control to have the user inputting their text, then set the content of the textbox put inside a label.

    2 - You want to have a string with placeholders and replace the placeholders with content from some textbox .

    For that you can user String.Format like this:

    String.Format("The textbox contains{0}", textbox1.text);


    Please clarify so we can answer you?

    Thanks,


    My Technet Articles

    If you like this or another reply, vote it up!
    If you think this or another reply answers the original question, mark it or propose it as an answer.


    Mauricio Feijo
    www.mauriciofeijo.com


    Tuesday, August 16, 2016 5:46 PM

All replies

  • You could try using the below code. Hope this helps you.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace PlaceHolderTbox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void textBox1_Enter(object sender, EventArgs e)
            {
                if(textBox1.Text=="Enter some text here")
                {
                    textBox1.Text = "";
                }
            }
    
            private void textBox1_Leave(object sender, EventArgs e)
            {
                if (textBox1.Text == "")
                {
                    textBox1.Text = "Enter some text here";
                    textBox1.ForeColor = Color.Gray;
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.Text = "Enter some text here";
            }
        }
    }

    pls marks as answer if your query is resolve.


    Tuesday, August 16, 2016 2:30 PM
  • Requirements are not clear.

    String.Format does support placeholders to be put into the string. It is used extensively by Console.WriteLine().
    Of course basic string conaction (+ operator) or StringBuilder can also work.

    Also ToString() and Convert functions can be modified heavily via parameters, if you need specific output formats (specific Culture, Number Format, base of the output).

    If this is about internationalisation - there is no easy answer here. Timezones are madness inducing bad. That is even worse:
    https://www.youtube.com/watch?v=0j74jcxSunY

    Tuesday, August 16, 2016 5:39 PM
  • Hi Sanjay,

    I guess we are having a hard time understanding your requirements. Is this for a homework assignment?

    If not can you tell us a line or two about the business scenario you are trying to resolve?

    Here are a couple of possible answers for you:

    1 - You want the user to enter text in a textbox, then you want the content of that textbox to be displayed to the user.

    If this is the case, use a textbox control to have the user inputting their text, then set the content of the textbox put inside a label.

    2 - You want to have a string with placeholders and replace the placeholders with content from some textbox .

    For that you can user String.Format like this:

    String.Format("The textbox contains{0}", textbox1.text);


    Please clarify so we can answer you?

    Thanks,


    My Technet Articles

    If you like this or another reply, vote it up!
    If you think this or another reply answers the original question, mark it or propose it as an answer.


    Mauricio Feijo
    www.mauriciofeijo.com


    Tuesday, August 16, 2016 5:46 PM