如何动态更改表格和组件的颜色 [英] How to change FORM and Component color dynamically

查看:110
本文介绍了如何动态更改表格和组件的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends
如何通过更改按钮等其他组件的颜色来动态更改Windows窗体应用程序的颜色,如何使用颜色选择器以不同的颜色组合来更改应用程序的颜色.请帮忙.

Hi Friends
How to change windows form application color dynamically with changing the color of other component like button etc., how i can use color picker to change the color of my application with different color combination. Please help.

推荐答案

使用System.Windows.Forms.Control.BackColorSystem.Windows.Forms.Control.ForeColor.有读/写属性,因此您可以随时修改任何控件(包括Form)的背景色或前景色.颜色(System.Drawing.Color)的分配将自动使控件的渲染无效,因此您所需要做的就是分配:

Use System.Windows.Forms.Control.BackColor and System.Windows.Forms.Control.ForeColor. There are read/write properties, so you can modify background or foreground color of any control (it includes Form) at any time. Assignment of the color (System.Drawing.Color) will automatically invalidate the control''s rendering, so all you need is assignment:

myButton.BackColor = System.Drawing.Colors.Wheat;



-SA



—SA


FormId.Color = Color.Red;


就像
您可以更改任何控件的颜色
FormId.Color=Color.Red;


like
that u can change color of any control


,假设您的表单的名称为frmLogin,并且您想动态更改前景色和背景色,并且如果用户名和密码错误,则可以使用登录"按钮,那么您想改变颜色..
所以代码会像这样...
suppose your form has name frmLogin and you want to change forecolor and backcolor dynamically and for that you have Login button if user name and password is wrong then you want to change the color..
so the code will like this...
private void frmLogin_Load(object sender, EventArgs e)
{
    // if user name and password is wrong then give some proper message and change the color like this...
    frmLogin.BackColor = System.Drawing.Color.Yellow;
    frmLogin.ForeColor = System.Drawing.Color.Red;
}



谢谢



Thanks,


这篇关于如何动态更改表格和组件的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆