This is a migrated thread and some comments may be shown as answers.

RadBrowseEditor - ForeColor of the text when control is disabled

6 Answers 197 Views
BrowseEditor
This is a migrated thread and some comments may be shown as answers.
Eric Moreau
Top achievements
Rank 2
Iron
Veteran
Iron
Eric Moreau asked on 14 May 2019, 07:21 PM

Hi

Using a RadBrowseEditor, how can I change at runtime (using code) the ForeColor of the text when control is disabled?

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 May 2019, 10:30 AM
Hello, Eric,     

Note that RadBrowseEditor internally uses a standard MS TextBox. When you disable it, the disabled state indicates gray back color and fore color as well no matter what is the applied ForeColor to the control itself. After some research, I have found the following general programming forum threads which suggest appropriate solutions for handling such a case: 
https://stackoverflow.com/questions/276179/how-to-change-the-font-color-of-a-disabled-textbox
https://social.msdn.microsoft.com/Forums/windows/en-US/de63a4e2-f453-49b3-ab0a-c338080681f0/how-to-change-a-disabled-textboxs-forecolor?forum=winforms

I believe that it would be applicable for your scenario as well and simulate disabling the control without actually manipulating the Enabled property. Thus, the visual style will be preserved 

Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.Thank you for your understanding.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eric Moreau
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 16 May 2019, 01:35 PM

Hi Dess

I would really to create tickets. I have a valid license but cannot create tickets (a MVP license I think).

As for your comments, I can't see how to apply the links you have provided since the standard MS Textbox is buried deep into your structure.

I event tried the tricks provided at https://www.telerik.com/support/kb/winforms/editors/details/changing-the-text-color-of-a-disabled-radtextbox without success. 

Any other hints? Or any chance to update the tricks from the link?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 May 2019, 12:30 PM
Hello, Eric,     

The easiest solution in this case is to simulate disabling the control without actually manipulating the Enabled property. Set the ReadOnly property to true. Thus, the visual style will be preserved. Please refer to the following code snippet:

public RadForm1()
{
    InitializeComponent();
 
    this.radBrowseEditor1.Value = @"C:\";
    this.radBrowseEditor1.ForeColor = Color.Red;
    this.radBrowseEditor1.ReadOnly = true;
    this.radBrowseEditor1.BrowseElement.TextBoxItem.TextBoxControl.MouseUp+=TextBoxControl_MouseUp;
 
}
 
private void TextBoxControl_MouseUp(object sender, MouseEventArgs e)
{
    this.radBrowseEditor1.BrowseElement.TextBoxItem.SelectionLength = 0;
}

As to the license and submitting tickets, I have already contacted our Sales team to investigate what is wrong with your account.

I hope this information helps. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eric Moreau
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 17 May 2019, 03:31 PM

Really not ideal! textbox can be clicked and take focus when ReadOnly only. 

Would the RadButtonTextBox be easier to manage disabled colors? Or should I just continue with my RadTextBoxControl with my own custom button to trigger the OpenFileDialog?

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 May 2019, 11:28 AM
Hello, Eric,     

Usually, when a WinForms control is disabled, it becomes gray. This is standard behavior even valid for TextBox. Since RadTextBox, RadBrowseEditor and other controls from the WinForms suite internally host the standard TextBox, this behavior can't be manipulated. That is why a general advice is to simulate the disabled state by read only behavior and disabled selection.

An alternative solution that I can suggest is to use a RadTextBoxControl which doesn't host any standard control. Hence, you can disable the default disabled painting for RadTextBoxControl and keep the fore color. RadTextBoxControl allows adding of a button to show the OpenFileDialog and manipulate the text displayed in the RadTextBoxControl. You can find below a sample code snippet:

    this.radTextBoxControl1.Text = "Test";
    this.radTextBoxControl1.ForeColor = Color.Red;
    this.radTextBoxControl1.TextBoxElement.UseDefaultDisabledPaint = false;
    this.radTextBoxControl1.RootElement.UseDefaultDisabledPaint = false;
 
    RadButtonElement btn = new RadButtonElement();
    btn.Text = ". . .";
    btn.Click += btn_Click;
    this.radTextBoxControl1.TextBoxElement.ClearButton.Parent.Children.Add(btn);
 
private void btn_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    DialogResult dr = ofd.ShowDialog();
    if (dr == System.Windows.Forms.DialogResult.OK)
    {
        this.radTextBoxControl1.Text = ofd.FileName;
    }
}




If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eric Moreau
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 21 May 2019, 12:57 PM
Thanks Dess for your support
Tags
BrowseEditor
Asked by
Eric Moreau
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Eric Moreau
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or