Solved

reset button background color - c#

Posted on 2014-07-29
7
1,714 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 34

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 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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