SearchBox

1 Answer 365 Views
TextBox
Jure
Top achievements
Rank 2
Iron
Iron
Iron
Jure asked on 10 Aug 2022, 08:47 AM

I need a search box and not wanting to (badly) reinvent the wheel I found this https://docs.telerik.com/devtools/winforms/knowledge-base/search-box

Can somebody help me improve this:

- I want the magnifying glass image on the left because it interferes with the clear button (Show clear button property). If I modify the code to dock it to the left (and the RadTextBoxItem to the right) the clear button isn't shown when it's supposed to..

- I want the magnifying glass image to disappear when the user focuses on the text box or when there's some text in it

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Aug 2022, 08:51 AM

Hello, Jure,

I believe that our RadButtonTextBox would be a better fit for your scenario:

It allows you to embed easily button elements on the left or right side of the text box. Please refer to the following help article to get started with this control:

https://docs.telerik.com/devtools/winforms/controls/editors/buttontextbox/getting-started 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Jure
Top achievements
Rank 2
Iron
Iron
Iron
commented on 11 Aug 2022, 06:52 AM

OK, thanks, this will do..
Jure
Top achievements
Rank 2
Iron
Iron
Iron
commented on 12 Aug 2022, 10:23 AM

Dess, can you help me out? I'm trying to make an inherited control from RadButtonTextBox. I add some LeftButtonItems and RightButtonItems but they're not retained when I drag a new instance of it on a form. Same for the ThemeName property. Maybe it's not possible? This is my code:

 


Imports Telerik.WinControls.UI

Public Class ASearchBox
    Inherits RadButtonTextBox

    Friend WithEvents RadImageButtonElement1 As RadImageButtonElement
    Friend WithEvents RadImageButtonElement2 As RadImageButtonElement
    Friend WithEvents RadCheckBoxElement1 As RadCheckBoxElement
    Private _coolShit As String

    Public Property CoolShit As String
        Get
            Return _coolShit
        End Get
        Set(value As String)
            _coolShit = value
        End Set
    End Property

    Private Sub InitializeComponent()
        Me.RadImageButtonElement1 = New Telerik.WinControls.UI.RadImageButtonElement()
        Me.RadImageButtonElement2 = New Telerik.WinControls.UI.RadImageButtonElement()
        Me.RadCheckBoxElement1 = New Telerik.WinControls.UI.RadCheckBoxElement()
        CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'RadImageButtonElement1
        '
        Me.RadImageButtonElement1.Image = Global.TraxCashFlow.My.Resources.Resources.search_16x16
        Me.RadImageButtonElement1.Margin = New System.Windows.Forms.Padding(2, 0, 0, 0)
        Me.RadImageButtonElement1.Name = "RadImageButtonElement1"
        Me.RadImageButtonElement1.Text = "RadImageButtonElement1"
        '
        'RadImageButtonElement2
        '
        Me.RadImageButtonElement2.Image = Global.TraxCashFlow.My.Resources.Resources.clear_16x16
        Me.RadImageButtonElement2.Margin = New System.Windows.Forms.Padding(2, 0, 0, 0)
        Me.RadImageButtonElement2.Name = "RadImageButtonElement2"
        Me.RadImageButtonElement2.Text = "RadImageButtonElement2"
        '
        'RadCheckBoxElement1
        '
        Me.RadCheckBoxElement1.Checked = False
        Me.RadCheckBoxElement1.Margin = New System.Windows.Forms.Padding(2, 0, 0, 0)
        Me.RadCheckBoxElement1.Name = "RadCheckBoxElement1"
        Me.RadCheckBoxElement1.ReadOnly = False
        Me.RadCheckBoxElement1.ShowBorder = False
        Me.RadCheckBoxElement1.Text = "RadCheckBoxElement1"
        '
        'ASearchBox
        '
        Me.LeftButtonItems.AddRange(New Telerik.WinControls.RadItem() {Me.RadImageButtonElement2})
        Me.NullText = "Search..."
        Me.RightButtonItems.AddRange(New Telerik.WinControls.RadItem() {Me.RadImageButtonElement1, Me.RadCheckBoxElement1})
        Me.ShowNullText = True
        Me.Size = New System.Drawing.Size(100, 27)
        Me.ThemeName = "Fluent"
        CType(Me, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
End Class

Jure
Top achievements
Rank 2
Iron
Iron
Iron
commented on 12 Aug 2022, 10:51 AM

Bah, both the autogenerated code and myself forgot to include this part:


 Public Sub New()
        InitializeComponent()
    End Sub
It's working now.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 12 Aug 2022, 12:49 PM

Hi, Jure,

I am glad that the problem you were facing is now resolved. However, I would like to note that when you inherit from a RadControl (or any RadControl descendant), the original control themes are not automatically inherited. Please refer to the following help article demonstrating how to inherit the theme as well:

https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/inherit-themes-from-radcontrols-derivatives 
Tags
TextBox
Asked by
Jure
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or