Click here to Skip to main content
15,894,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 31-Jul-12 0:58am
v3

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:
C#
Form2 f2 = new Form2();
if (f2.ShowDialog == DialogResult.OK)
   {
   if (f2.UpdatedOK)
      {
      myButton.BackColor = Color.Green;
      }
   }

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.
 
Share this answer
 
ButtonName.Background=Brushes.Red;

By using above code you can change button color dynamically.
 
Share this answer
 
Comments
Dhinesh kumar.V 31-Jul-12 10:16am    
Thanks for your reply. But i dont need to change color dynamically. now i improve my question. so please see that and send your valuable reply. Thanks in Advance.....

Dhinesh Kumar.V
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900