none
Hide button text RRS feed

  • Question

  • I have button1 on my form.
    button1.Text = "blabla";

    Now I want to hide this "blabla".

    Sunday, November 1, 2009 2:51 PM

Answers

  • you can make a new classButton which holds a string with the text you want the rest of your program to read. 
    then use property to get/set this value and methods to show/hide the text on the button which the user sees.

    here's what i wrote (my test form has two buttons already the events shown below):

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            classButton newButton = new classButton();
            public Form1()
            {
                InitializeComponent();
                newButton.HiddenText = "my hidden button";
                newButton.showText();
                Controls.Add(newButton);
                newButton.AutoSize = true;
                newButton.Top = 5; newButton.Left = 5;
                newButton.Visible = true;
            }
            private void btnHideButton_Click(object sender, EventArgs e) { newButton.hideText(); }
            private void btnShowButton_Click(object sender, EventArgs e) { newButton.showText(); }
        }
    
        public class classButton : Button
        {
            public string strHiddenText;
    
            public string HiddenText
            {
                get { return strHiddenText; }
                set { strHiddenText = value; }
            }
    
            public void hideText() { Text = ""; }
            public void showText() { Text = strHiddenText; }
        }
    }
    








    my code is perfect until i don't find a bug
    • Marked as answer by wartmignef Sunday, November 1, 2009 4:56 PM
    Sunday, November 1, 2009 3:44 PM

All replies

  • you could just set it to an empty string :

    button1.Text = "";
    or set the forecolor = backcolor

    button1.ForeColor = button1.BackColor;
    hope that helps,
    BadButBit
    my code is perfect until i don't find a bug
    Sunday, November 1, 2009 3:05 PM
  • Or use button1.Hide();

    Noam B
    ______________________________________________________________________

    Do not Forget to Vote as Helpful, Please. It encourages us to help you...
    Sunday, November 1, 2009 3:13 PM
  • I cant do button1.text = ""; because this text is used by other functions in my program...

    I cant use the same backcolor because I have a background image on my button...

    I cant hide button because it must be there...



    Sunday, November 1, 2009 3:17 PM
  • you can make a new classButton which holds a string with the text you want the rest of your program to read. 
    then use property to get/set this value and methods to show/hide the text on the button which the user sees.

    here's what i wrote (my test form has two buttons already the events shown below):

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            classButton newButton = new classButton();
            public Form1()
            {
                InitializeComponent();
                newButton.HiddenText = "my hidden button";
                newButton.showText();
                Controls.Add(newButton);
                newButton.AutoSize = true;
                newButton.Top = 5; newButton.Left = 5;
                newButton.Visible = true;
            }
            private void btnHideButton_Click(object sender, EventArgs e) { newButton.hideText(); }
            private void btnShowButton_Click(object sender, EventArgs e) { newButton.showText(); }
        }
    
        public class classButton : Button
        {
            public string strHiddenText;
    
            public string HiddenText
            {
                get { return strHiddenText; }
                set { strHiddenText = value; }
            }
    
            public void hideText() { Text = ""; }
            public void showText() { Text = strHiddenText; }
        }
    }
    








    my code is perfect until i don't find a bug
    • Marked as answer by wartmignef Sunday, November 1, 2009 4:56 PM
    Sunday, November 1, 2009 3:44 PM
  • Put your button's text also in tag property of button.

    and when you set the text property to "" read the value from tag property.
    Sunday, November 1, 2009 3:45 PM
  • Just use the

    button1.text = " ";

    and

    button1.text = "blabla";

    for returning the text value of the button


    :)
    Sunday, November 1, 2009 3:48 PM