I am trying a project with Telerik Winform in C#, and wish to get the parent control of RightButtonItem
(RadButtonElement
) from a ButtonTextBox
, which is the ButtonTextBox
itself.
Tried using control.Parent
property, but the returned object is not the ButtonTextBox
control.
Any help is very appreciated.
Thanks to @Dess for the answer.
One of my codes using this:
public void ButtonTextBox_Clear(object sender, EventArgs e)
{
object obj = sender as RadButtonElement.ElementTree.Control;
RadButtonTextBox parent = obj as RadButtonTextBox;
parent.Clear();
}
CodePudding user response:
The RightButtonItems collection contains different RadButtonElements. If you want to detect the parent control from one of the internal RadButtonElements, the easiest way to do it is to use the RadButtonElement.ElementTree.Control and cast it to RadButtonTextBox.
Dictionary<int, string> glyphs = new Dictionary<int, string>();
List<RadButtonElement> buttons = new List<RadButtonElement>();
glyphs.Add(0, "");
glyphs.Add(1, "");
glyphs.Add(2, "");
for (int i = 0; i <= 9 - 1; i )
{
RadButtonElement radButtonElement = new RadButtonElement();
radButtonElement.DisplayStyle = Telerik.WinControls.DisplayStyle.Text;
radButtonElement.TextElement.CustomFont = "TelerikWebUI";
radButtonElement.TextElement.CustomFontSize = 10;
radButtonElement.TextElement.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
radButtonElement.Text = glyphs[i];
buttons.Add(radButtonElement);
}
radButtonTextBox1.RightButtonItems.AddRange(buttons[0]);
radButtonTextBox1.LeftButtonItems.AddRange(buttons[1], buttons[2]);
radButtonTextBox1.AutoSize = false;
radButtonTextBox1.Text = "";
RadButtonTextBox btnTextBox = buttons[1].ElementTree.Control as RadButtonTextBox;