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

rad masked textbox nulltext question.

4 Answers 140 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
regina
Top achievements
Rank 1
regina asked on 08 Feb 2011, 07:24 PM
Is there a way to only have the nulltext italisized?  I do not want the entered text by the user to be italisized.  This seems like it would be a pretty popular thing so it seems like there must be a way , thanks in advance.
regina.

4 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 09 Feb 2011, 11:12 AM
Hello,

As far as I'm aware, it is not currently possible to change the font italics of the null text.
Regards,
Richard
0
Ivan Petrov
Telerik team
answered on 11 Feb 2011, 10:56 AM
Hello regina,

Thank you for contacting us. You should use code to provide this functionality. Please consider the following code snippet:

private Font regularFont;
private Font italicFont;
 
public Form1()
{
   InitializeComponent();
 
   Font editorFont = this.radMaskedEditBox1.Font;
 
   this.regularFont = new Font(editorFont.FontFamily, editorFont.SizeInPoints, FontStyle.Regular);
   this.italicFont = new Font(editorFont.FontFamily, editorFont.SizeInPoints, FontStyle.Italic);
}
         
private void radMaskedEditBox1_Enter(object sender, EventArgs e)
{
   this.radMaskedEditBox1.Font = regularFont;
}
 
private void radMaskedEditBox1_Leave(object sender, EventArgs e)
{
   if (this.radMaskedEditBox1.Text.Length == 0)
   {
       this.radMaskedEditBox1.Font = italicFont;
   }
}

It's a good idea to have the fonts created once because the creation of a Font is a heavy operation and can lead to memory leaks.

I hope this will help you. If you need further assistance I would be glad to provide it.

Regards,
Ivan Petrov
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Richard Slade
Top achievements
Rank 2
answered on 11 Feb 2011, 11:14 AM
Hi,

I've learnt something new here. Thanks.

May I suggest a slight change though. we can cut down on the number of events called and also we need to ensure that this is called from from_load as well in case the RadMaskedEditBox does not have a value when the form loads

private void radMaskedEditBox1_TextChanged(object sender, EventArgs e)
{
    if (this.radMaskedEditBox1.Text.Length == 0)
    {this.radMaskedEditBox1.Font = italicFont;}
    else
    {this.radMaskedEditBox1.Font = regularFont;}
}

and in form load
radMaskedEditBox1_TextChanged(null, null);

Hope that helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 11 Feb 2011, 01:21 PM
@Ivan,
Actually, your way will fire less, and so better, but this would still need the check on load
if (this.radMaskedEditBox1.Text.Length == 0)
{
    this.radMaskedEditBox1.Font = italicFont;
}
Richard
Tags
TextBox
Asked by
regina
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Ivan Petrov
Telerik team
Share this question
or