加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何更改TextBox的背景颜色?

发布时间:2020-12-15 06:09:23 所属栏目:百科 来源:网络整理
导读:我有C#代码,就像: if(smth == "Open"){ TextBox.Background = ???} 如何更改TextBox的背景颜色? 解决方法 如果是WPF,则静态类画笔中会显示一组颜色. TextBox.Background = Brushes.Red; 当然,如果需要,您可以创建自己的画笔. LinearGradientBrush myBrush
我有C#代码,就像:
if(smth == "Open")
{
    TextBox.Background = ???
}

如何更改TextBox的背景颜色?

解决方法

如果是WPF,则静态类画笔中会显示一组颜色.
TextBox.Background = Brushes.Red;

当然,如果需要,您可以创建自己的画笔.

LinearGradientBrush myBrush = new LinearGradientBrush();
myBrush.GradientStops.Add(new GradientStop(Colors.Yellow,0.0));
myBrush.GradientStops.Add(new GradientStop(Colors.Orange,0.5));
myBrush.GradientStops.Add(new GradientStop(Colors.Red,1.0));
TextBox.Background = myBrush;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读