help: add icon in textbox

2 posts, 0 answers
  1. ricric
    ricric avatar
    12 posts
    Member since:
    Sep 2010

    Posted 21 Jul 2011 Link to this post

    how to add an icon to the textbox in radcommandbar? i want to make a search box with icon in the right align.
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 26 Jul 2011 Link to this post

    Hello Ricric,

    Thank you for writing.

    In order to add an item to the RadTextBoxElement, please consider the following code snippet:

    private void AddIconToTextBoxElement(RadTextBoxElement textElement, ImagePrimitive icon)
    {
      RadTextBoxItem item = textElement.TextBoxItem;
     
      textElement.Children.Remove(item);
     
      icon.SetValue(DockLayoutPanel.DockProperty, Telerik.WinControls.Layouts.Dock.Left);
     
      DockLayoutPanel dockPanel = new DockLayoutPanel();
      dockPanel.LastChildFill = true;
     
      dockPanel.Children.Add(icon);
      dockPanel.Children.Add(item);
     
      textElement.Children.Add(dockPanel);
    }

     You can initialize the ImagePrimitive as in the following code snippet:
    ImagePrimitive icon = new ImagePrimitive();
    icon.Image = Properties.Resources.icon;

    In addition, you should note that you can use the same technique to add any RadElement like RadButtonElement, RadProgressbarElement etc.

    You can call this method in your form constructor after InitializeComponent().

    I hope this will be useful for your. If you have further questions, feel free to ask. Best wishes,
    Ivan Petrov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top