rad masked textbox nulltext question.

5 posts, 0 answers
  1. regina
    regina avatar
    40 posts
    Member since:
    Sep 2012

    Posted 08 Feb 2011 Link to this post

    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.
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 09 Feb 2011 Link to this post

    Hello,

    As far as I'm aware, it is not currently possible to change the font italics of the null text.
    Regards,
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 11 Feb 2011 Link to this post

    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.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Feb 2011 Link to this post

    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
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Feb 2011 Link to this post

    @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
Back to Top
UI for WinForms is Visual Studio 2017 Ready