Solved

reset button background color - c#

Posted on 2014-07-29
7
1,549 Views
Last Modified: 2014-07-29
I have used the following to reset button color:

Note that btn12 has no settings (its blank and gets its style from a css file). So instead of: btn.BackColor = ""; or btn.BackColor = null; I have used btn.BackColor = btn12.BackColor;

At line 14 (var c = btn12.BackColor;) no settings for btn12 reads c="{Name=0, ARGB(0,0,0,0)}", and
At line 15 (c = btn.BackColor;) the settings for the current btn reads c="{Name=Orange, ARGB(255,255,165,0)}",

Question: Can I then replace line 5 (btn.BackColor = btn12.BackColor;) with:

btn.BackColor = "{Name=0, ARGB(0,0,0,0)}";

Because neither of btn.BackColor = ""; or btn.BackColor = null; work.

Thank you.
 int i;
       for (i = 1; i < 11; i++)
        {
            Button btn = (Button)this.FindControl("btn" + i.ToString());
           btn.BackColor = btn12.BackColor;
        }


        if (Session["pressedButton"] != null)
        {
            string strButton = Session["pressedButton"].ToString();
            Button btn = (Button)this.FindControl(strButton);
            btn.BackColor = Color.Orange;
            var c = btn12.BackColor;
            c = btn.BackColor;
        }

Open in new window

0
Comment
Question by:Mike Eghtebas
  • 4
  • 3
7 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40227274
You would use something of this sort, or System.Drawing.Color.Orange if you want to reference by name.
btn .BackColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);

Open in new window

0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40227327
Hi Randy,

This gives black background to the buttons. It doesn't clear its backcolor property. I understand your logic but there has to be something else.

{Name=0, ARGB(0,0,0,0)}   <-- name argument is not set to zero in your code and I don't know how this part is done.

Mike
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40227346
that will give A black, rgb 000 is black if your trying to clear it, (make it transparent)
btn.BackColor = System.Drawing.Color.Transparent;

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40227365
btn.BackColor = System.Drawing.Color.Transparent;

makes it transparent. It is not the same as nothing set.

Therefore, transparent setting doesn't allow css setting work. It just makes the buttons transparent.

Mike
0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40227409
Hmm.
You can also try one of these:
btn.BackColor = System.Drawing.Color.FromName("0");

Open in new window

or
btn.BackColor = System.Drawing.Color.Empty;

Open in new window

or
btn.BackColor = System.Drawing.Color.FromName(null);

Open in new window

0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40227460
First two work okay:

btn.BackColor = System.Drawing.Color.FromName("0");
btn.BackColor = System.Drawing.Color.Empty;


but not the last:
btn.BackColor = System.Drawing.Color.FromName(null);

Thanks,

Mike
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40227583
NP
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now