Solved

reset button background color - c#

Posted on 2014-07-29
7
1,508 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
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.

744 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

13 Experts available now in Live!

Get 1:1 Help Now