[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1367
  • Last Modified:

Text color on disabled label control

Maybe this is kind of a silly question, but I have a problem with changing the color of the text in disabled label control. It must be disabled, but I want not to be grey and not to be in 3D (I want to be flat text, without shades). Any help will be appreciated.

Thanks in advance...
0
MilanJ
Asked:
MilanJ
  • 3
  • 2
1 Solution
 
tomvergoteCommented:
are you sure it's a label and not a linklabel or a button or something?
Are you talking about webforms or winforms?
0
 
Chester_M_RagelCommented:
And why you want to make a label dissabled?
0
 
MilanJAuthor Commented:
It is a label, but I tried a linklabel that has property "Disabled Link Color", and  it ignores my text color also (it is also grey and with shades). With linklabel I tried this in InitializeComponent:

this.lblReport.Enabled = false;
this.lblReport.DisabledLinkColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(102)));

I'm talking about winforms.

I want to make label disabled because it is on the panel, and when mouse comes over the label (and label is enabled) my panel looses focus, and I need focus on my panel all the time because you can click on panel all the time (some kind simulation of a button, but a bit more complex one).

Maybe my english is not good, but I think you can understand what I mean.  
0
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!

 
Chester_M_RagelCommented:
You could override OnPaint in a derived class and handle drawing the text string in your override, thus allowing you to use whatever color you wanted to use.

For example a custom label control,

using System;
using System.Drawing;
using System.Windows.Forms;

namespace MyNameSpace
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      public class MyLabel : Label
      {
            protected override void OnPaint(PaintEventArgs e)
            {
                  
                  Brush br = new SolidBrush(Color.Blue);
                  e.Graphics.DrawString(this.Text,this.Font,br,this.ClientRectangle);
            }

            public MyLabel()
            {
                  //
                  // TODO: Add constructor logic here
                  //
            }
      }
}

0
 
MilanJAuthor Commented:
@Chester M Regal
Thanks, but when I do that, I cannot see my form in design view (although this solution works just fine when I start the project), but this is (from my point of view) normal behaviour because I destroy its original OnPaint.

But, I came out with another solution, and I think this will work fine, too (and it doesn't break down the design view):

In InitializeComponent:
this.lblReport.Paint += new System.Windows.Forms.PaintEventHandle(this.lblReport_Paint);

and then:
private void lblReport_Paint(object sender, PaintEventArgs e)
{
    Brush br = new SolidBrush(Color.Red);
    e.Graphics.DrawString(this.lblReport.Text, this.lblReport.Font,br, this.lblReport.ClientRectangle);
}

What do you think?
0
 
Chester_M_RagelCommented:
>Thanks, but when I do that, I cannot see my form in design view (although this solution works just fine when I start the >project), but this is (from my point of view) normal behaviour because I destroy its original OnPaint.

>But, I came out with another solution, and I think this will work fine, too (and it doesn't break down the design view):
If you create that in a new project you can get the view..


>In InitializeComponent:
>this.lblReport.Paint += new System.Windows.Forms.PaintEventHandle(this.lblReport_Paint);

>and then:
>private void lblReport_Paint(object sender, PaintEventArgs e)
>{
>   Brush br = new SolidBrush(Color.Red);
>    e.Graphics.DrawString(this.lblReport.Text, this.lblReport.Font,br, this.lblReport.ClientRectangle);
>}
>
>What do you think?

This is another way(easy:)) of achiving the same task.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now