数据库值更改时更改按钮颜色 [英] change button colour when database value change

查看:143
本文介绍了数据库值更改时更改按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,


是C#.Net的新功能.现在我有一个问题.我有两种形式和

带有一个按钮的form1(提交).当我单击该按钮时,下一个表单(Form2)已打开

然后我输入了一些详细信息并添加到数据库中.成功添加数据后

我的Form1颜色的提交"按钮已更改.这是怎么回事...全部回复欢迎.


在此先感谢

Dhinesh kumar.V

Dear All,


Am new for c# .Net. Now i have one problem. I have two forms and

form1 having one button(Submit). When am click that button next form(Form2) is open

and there i entered some details and add into database. After add data successfully

my Submit button from Form1 color is changed. How do this one... All replies Welcome.


Thanks in Advance

Dhinesh kumar.V

推荐答案

取决于您如何显示Form2.
如果通过ShowDialog显示它,则必须添加一个返回代码作为属性(或使用DialogResult返回),然后对其进行查询:
Depends on how you are showing the Form2.
If you show it via ShowDialog, then you will have to add a return code as a property (or use the DialogResult return) which you then interrogate:
Form2 f2 = new Form2();
if (f2.ShowDialog == DialogResult.OK)
   {
   if (f2.UpdatedOK)
      {
      myButton.BackColor = Color.Green;
      }
   }


如果使用Show而不是ShowDialog,则需要在Form2中创建第一个表单处理的事件.在处理程序中设置颜色.


If you use Show instead of ShowDialog, then you need to create an event in Form2 which your first form handles. In the handler you set the colour.


ButtonName.Background = Brushes.Red;

通过使用上面的代码,您可以动态更改按钮的颜色.
ButtonName.Background=Brushes.Red;

By using above code you can change button color dynamically.


我认为您应该在form2中使用委托来更改form1按钮的颜色,
尝试此链接以获取帮助,否则,如果您遇到编码问题,请告诉我

http://www.dotnetfunda.com/Articles/article904-6-important-uses-delegates-and-events.aspx#Multicast%20delegates [
I think you should use delegate in form2 to change the colour of form1 button,,
try this link for help,otherwise let me know if you have coding issue

http://www.dotnetfunda.com/articles/article904-6-important-uses-of-delegates-and-events.aspx#Multicast%20delegates[^]


这篇关于数据库值更改时更改按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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