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


    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  
            AddHandler btnElement.Click, AddressOf btnClearSearh_Click 

  2. Martin Vasilev
    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   
    DockLayoutPanel.SetDock(textBoxItem, Telerik.WinControls.Layouts.Dock.Left)   
    DockLayoutPanel.SetDock(buttonElement, Telerik.WinControls.Layouts.Dock.Right)   
    Dim dockLayoutPanel As New 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.
Back to Top