Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, November 1, 2009 2:51 PM
I have button1 on my form.
button1.Text = "blabla";
Now I want to hide this "blabla".
All replies (6)
Sunday, November 1, 2009 3:44 PM âś…Answered
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
Sunday, November 1, 2009 3:05 PM
you could just set it to an empty string :
button1.Text = "";
or set the forecolor = backcolor
button1.ForeColor = button1.BackColor;
hope that helps,
BadButBitmy code is perfect until i don't find a bug
Sunday, November 1, 2009 3:13 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:17 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:45 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:48 PM
Just use the
button1.text = " ";
and
button1.text = "blabla";
for returning the text value of the button
:)