Solved

change the background color opacity of a button - c#

Posted on 2014-07-29
6
1,429 Views
Last Modified: 2014-07-31
On a page I have bt1, btn2, bt3.

Via code I want to add opacity of .5 to btn1 and remove it from other two. Depending on the logic of the code, I may need to have btn2 with .5 opacity and the rest at 0.

Question: How is this done in code window?

Thank you.
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
  • 3
  • 2
6 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40227882
bt1.BackColor = System.Drawing.Color.FromArgb(128,bt1.BackColor);

Open in new window

this will set the alpha to 50%
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40227945
How would one know this is 50% opacity? Knowing this will help to change to 25% or 75% later on when a need arises?

I do not see number 0.0 in your code.

Is FromArgb(64,bt1.BackColor); then 25%

Mike

BTW, after I tried this code, I don't see any opacity change.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40231863
What kind of project is this? Web forms? Win Forms? WPF?
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: 40231983
Web form.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40232016
You can add a style to your buttons in the code behind:

this.Button1.Style.Add("opacity", "1");
this.Button2.Style.Add("opacity", ".5");
this.Button3.Style.Add("opacity", "1");

Open in new window


The more preferable approach would be to use CSS classes:

this.Button1.CssClass = "opacity-100";
this.Button2.CssClass = "opacity-100";
this.Button3.CssClass = "opacity-50";

Open in new window


your.css
.opacity-50 {
    opacity: .5;
}

.opacity-100 {
    opacity: 1;
}

Open in new window


One problem you will have, though, is that the CssClass property is of type string, so if you have other CSS classes to add to your buttons, then you will need to do string manipulation in order to set the classes properly in your HTML.
0
 
LVL 34

Author Closing Comment

by:Mike Eghtebas
ID: 40232194
Thank you for good solution and etc.

Mike
0

Featured Post

Technology Partners: 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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