Button inside of a textbox

2 posts, 0 answers
  1. Nick Anderson
    Nick Anderson avatar
    40 posts
    Member since:
    May 2009

    Posted 21 May 2009 Link to this post

    Hi,

    Is there a way to place a button inside of a textbox?

    Here's my scenario:
    A user has a textbox to enter words that they wish to search for. After they have searched and they want to clear the results, i want to have a button (a red x button or something) that shows up at the end of the textbox (inside the textbox) allow them to clear the textbox and search results.

    I've tried making a RadButtonElement and adding it to the TextBoxElement.Children but the button appears to show up behind the textbox element. I can see and click on the very bottom edge of the textbox and fire the event handler.

            Dim btnElement As New RadButtonElement  
            btnElement.Text = "try this" 
            btnElement.Size = New Drawing.Size(20, 20)  
     
            Dim textboxElement As RadTextBoxElement = txtSearchFor.TextBoxElement  
     
            textboxElement.Children.Add(btnElement)  
            AddHandler btnElement.Click, AddressOf btnClearSearh_Click 

    Thanks
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 25 May 2009 Link to this post

    Hello Nick Anderson,

    Thank you for writing. You are approaching the issue in the right way. You just need to add an element that handles layout between text box item and button element. Please, review the code-block below:

    Dim buttonElement As New RadButtonElement("click me")   
    AddHandler buttonElement.Click, AddressOf buttonElement_Click   
     
    Dim textBoxItem As RadTextBoxItem = Me.radTextBox1.TextBoxElement.TextBoxItem   
    textBoxItem.Alignment = ContentAlignment.MiddleLeft   
     
    Me.radTextBox1.TextBoxElement.Children.Remove(textBoxItem)   
     
    DockLayoutPanel.SetDock(textBoxItem, Telerik.WinControls.Layouts.Dock.Left)   
    DockLayoutPanel.SetDock(buttonElement, Telerik.WinControls.Layouts.Dock.Right)   
     
    Dim dockLayoutPanel As New DockLayoutPanel()   
     
    dockLayoutPanel.Children.Add(buttonElement)   
    dockLayoutPanel.Children.Add(textBoxItem)   
     
    Me.radTextBox1.TextBoxElement.Children.Add(dockLayoutPanel)  

    Hope this helps. Do not hesitate to contact me again if you have other questions.

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top