简体   繁体   中英

How do you set text color of disabled form control button

I am trying to set the color of text in a control button to the same color of the control when it is disabled. In other words... I don't want any text to show when button is disabled.

I don't know how else to phrase this question.

It is just important for the text not to appear when disabled.

Thank you for your help.

Suppose you button is "button2". Then you can write this in button2's Enable_changed event. You can select the event from the properties window.

private void button2_EnabledChanged(object sender, EventArgs e)
{
    if (((Button)sender).Enabled)
    {
       button2.Text = "Button";
    }
    else
    {
       button2.Text = "";
    }
}

Then whenever you want you can call as

button2.Enabled = true 

Or you can set it to false. Tryout and respond. Bye

Set visibiliy of control to false.

If you don't want to display text

  1. you can hide button

    button.Visible=false;

OR

  1. you can set text to empty

    button.Text="";

See also my question Change TextColor of disabled control

Updated Answer

Possible approaches other than setting the Button1.ForeColor :

  • Set the Text property to String.Empty
  • You can set an alternate image which can be displayed instead of the control when it is disabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM