Solved

reset button background color - c#

Posted on 2014-07-29
7
1,653 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 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
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!

 
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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
linq, c# 8 31
C# Linq Select From List 3 42
Include MS Database in Winforms Project using Intellilock 5 21
global Variable - 2 functions in powershell 1 19
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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