Nested Custom User control with MaskedTextBox

9 posts, 1 answers
  1. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 08 Mar Link to this post

    I am fairly new to Telerik winforms. I have this issue that I have no idea how to troubleshoot. Can someone help please? 

    I made two base user controls that one contains a RadLabel and MaskedTextBox, and another contains Raddropdownlist and RadLabel. And then I put these two base user controls to third user control. Now I want to change the textbox background color of MaskedTextBox and RadDropDownList inside the third user control, when the third control is loaded.

    Inside the ThirdControl_Load function, I can use the following code to change the background color of RadDropDownList: 

    radDropdownlist1.radDropDownList.DropDownListElement.EditableElement.BackColor = Color.Red;

    However, I can not do the same thing to MaskedTextBox. There is no such an option for me to get to the MaskedTextBox elements. Basically, after I type

    maskedTextBox1.
    unlike the dropdownlist above, there is no radMaskedTextBox field to choose. Can anyone show me how to find the reference to maskedTextBox properties inside the third control, please? Thank you!

  2. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 08 Mar in reply to Ke Link to this post

    Let me change the code a bit so that it is easier to understand. 

    private void ThirdControl_Load(object sender, EventArgs e){
        DropDownListBaseControl.radDropDownList.DropDownListElement.EditableElement.BackColor = Color.Red; (This one Works)

        MaskedTextBoxBasecontrol.(not sure which field to choose to change the textbox backcolor)

    }

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 08 Mar Link to this post

    I figured out why the radDropDownList properties can be inherited by the custom user control. It is because a constructor can be set up. Here is the code: 

    public RadDropDownList radDropDownList
    {
        get
        {
            return radDropDownListCustom;
        }
        set
        {
            radDropDownListCustom = value;
        }
    }

    But I still can not figure out how to do the same with radMaskedEditBox.  

  5. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 09 Mar in reply to Ke Link to this post

    Never mind my previous post, it did not work properly. 

    Just for someone who doesn't know the basics, you need to go to designer file, and change Private to Public if you need to access all default items from Telerik. 

  6. Answer
    Dess
    Admin
    Dess avatar
    1605 posts

    Posted 10 Mar Link to this post

    Hello Ke,

    Thank you for writing.

    Following the provided information, I have prepared a sample project demonstrating how to customize the BackColor for RadMaskedEditBox. Please refer to the attached zip file and screenshot illustrating the result.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  7. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 10 Mar in reply to Dess Link to this post

    Thank you for your examples. They are great to understand. 
    I did exactly the same thing to change the backcolor of dropdownlist. And last night I realized that both my ways of changing accessibility to visual elements are correct. Thank you again for your examples to confirm.  
  8. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 10 Mar in reply to Dess Link to this post

    It's kinda embarrassing, but I just realized that there are also textbox properties under dropdownlistelement:

    this.radDropDownList.DropDownListElement.TextBox.Fill.BackColor;
    this.radDropDownList.DropDownListElement.TextBox.BackColor;     
  9. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 10 Mar Link to this post

    It's kinda embarrassing, but I just realized that there are also textbox properties under dropdownlistelement:

    this.radDropDownList.DropDownListElement.TextBox.Fill.BackColor = Color.Aqua <br>this.radDropDownList.DropDownListElement.TextBox.BackColor = Color.Aqua   

    In your code, you used: 

    this.userControl21.DropDown.DropDownListElement.EditableElement.TextBox.BackColor = Color.Aqua;
    this.userControl21.DropDown.DropDownListElement.EditableElement.TextBox.Fill.BackColor = Color.Aqua;

    what are the differences between these two? why are there two sets of codes that do exactly the same thing? 

    FYI: I accidentally press Tab and Enter at the same time and submitted one extra post. I can't delete my previous post. I apologize for any inconvenience that may cause to you. 

  10. Dess
    Admin
    Dess avatar
    1605 posts

    Posted 11 Mar Link to this post

    Hello Ke,

    Thank you for writing back. 

    Note that when the DropDownStyle property is set to DropDown, the TextBox. That is why you have access to the text box properties. The TextBox property exposes the TextBox. That is why they both do the same job as they are actually one and same element.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you need help with upgrading your Telerik API Analyzer and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready