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

Button inside of a textbox

3 Answers 156 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Nick Anderson
Top achievements
Rank 1
Nick Anderson asked on 21 May 2009, 06:42 PM
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

3 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 25 May 2009, 07:04 AM
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.
0
MaiK
Top achievements
Rank 1
answered on 28 Nov 2019, 04:06 PM

Hello,

I use that solution and button works well, but I have a little problem with theme. In the application theme is applied to entire app and in that custom button I need to remove theme. I try setting to False ShouldApplyTheme property, and nothing happend. I set theme with that code:

theme = new MyTheme();
ThemeResolutionService.ApplicationThemeName = "MyTheme";

How can I remove theme from button?

 

Thank you!

 

0
Nadya
Telerik team
answered on 29 Nov 2019, 11:52 AM

Hello Maik,

The ApplicationThemeName property affects the whole application. In this case, when you have an element within control, the possible solution is to create a custom button that inherits from the RadButtonElement and overrides its ThemeEffectiveType method:

CustomButtonElement buttonElement = new CustomButtonElement("click me");
 public class CustomButtonElement : RadButtonElement
    {
        public CustomButtonElement(string text) : base(text)
        {
        }

        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(CustomButtonElement);
            }
        }
    }

However, I have noticed that you refer to a quite old thread since 2009. Currently, there is a RadButtonTextBox in Telerik UI for Winforms suite. Could you please take a look at the following documentation article and see whether the RadButtonTextBox is suitable for you: https://docs.telerik.com/devtools/winforms/controls/editors/buttontextbox/buttontextbox

The following KB article is quite useful on the question about disabling the theme for a RadControl: https://www.telerik.com/support/kb/winforms/details/radcontrols-with-no-themes-radcontrols-with-replaced-controldefault-theme.

I hope this information helps. Should you have any other questions, I will be glad to help.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TextBox
Asked by
Nick Anderson
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
MaiK
Top achievements
Rank 1
Nadya
Telerik team
Share this question
or