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

Remove button from textbox

1 Answer 92 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 20 Aug 2012, 10:44 AM
Helo,

Following on from a piece of code I found in the forums which shows how to add a button to a text box. I can't seem to figure out how to remove it! - Can anybody help?

Thanks
Public Sub AddButton()
 
        Dim buttonElement As New RadButtonElement("...")
        AddHandler buttonElement.Click, AddressOf buttonElement_Click
 
        Dim textBoxItem As RadTextBoxItem = Me.RadTextBox1.TextBoxElement.TextBoxItem
        textBoxItem.Alignment = ContentAlignment.MiddleLeft
        Me.RadTextBox1.TextBoxElement.Children.Remove(textBoxItem)
 
         
 
        Dim dockLayoutPanel As New DockLayoutPanel()
 
        dockLayoutPanel.SetDock(textBoxItem, Telerik.WinControls.Layouts.Dock.Left)
        dockLayoutPanel.SetDock(buttonElement, Telerik.WinControls.Layouts.Dock.Right)
 
 
        dockLayoutPanel.Children.Add(buttonElement)
        dockLayoutPanel.Children.Add(textBoxItem)
        Me.RadTextBox1.TextBoxElement.Children.Add(dockLayoutPanel)
 
    End Sub

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 23 Aug 2012, 06:24 AM
Hello Terry,

Thank you for writing.

Here are a couple of methods demonstrating how to completely remove the button, how to hide it and how to show it, considering that you added it with the method mentioned:
     Sub RemoveButton()
       Me.RadTextBox1.TextBoxElement.Children(2).Children.RemoveAt(0)
   End Sub
 
   Sub HideButton()
       Me.RadTextBox1.TextBoxElement.Children(2).Children(0).Visibility = Telerik.WinControls.ElementVisibility.Collapsed
   End Sub
 
   Sub ShowHiddenButton()
       Me.RadTextBox1.TextBoxElement.Children(2).Children(0).Visibility = Telerik.WinControls.ElementVisibility.Visible
   End Sub

I hope that you find this information useful.
 
Regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
TextBox
Asked by
Terry
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or