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

Nested Custom User control with MaskedTextBox

8 Answers 116 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Ke
Top achievements
Rank 1
Ke asked on 08 Mar 2016, 07:35 PM

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!

8 Answers, 1 is accepted

Sort by
0
Ke
Top achievements
Rank 1
answered on 08 Mar 2016, 07:49 PM

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)

}

0
Ke
Top achievements
Rank 1
answered on 09 Mar 2016, 02:50 AM

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.  

0
Ke
Top achievements
Rank 1
answered on 09 Mar 2016, 07:43 PM

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. 

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Mar 2016, 11:39 AM
Hello ,

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.
0
Ke
Top achievements
Rank 1
answered on 10 Mar 2016, 05:13 PM
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.  
0
Ke
Top achievements
Rank 1
answered on 10 Mar 2016, 07:19 PM

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;     
0
Ke
Top achievements
Rank 1
answered on 10 Mar 2016, 07:29 PM

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. 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Mar 2016, 01:56 PM
Hello ,

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
Tags
TextBox
Asked by
Ke
Top achievements
Rank 1
Answers by
Ke
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or