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

Name with icon

2 Answers 20 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
MaiK
Top achievements
Rank 1
MaiK asked on 14 May 2018, 04:05 PM

Hi there!

 

Im working with property grid, and I need to put an image with property name.

I have achieved it, but I need give some margin betwen image and text.(See attached image)

I used that code:

Private Sub PropertyGridParams_ItemFormatting(sender As Object, e As UI.PropertyGridItemFormattingEventArgs) Handles PropertyGridParams.ItemFormatting
    
                        e.VisualElement.Image = New Bitmap(ImagePath, New Size(18, 18))
                        e.VisualElement.ImageAlignment = ContentAlignment.MiddleRight
                 
 
End Sub

How can I set custom image without cover the text?

 

Thank you!

 

2 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 15 May 2018, 09:59 AM
Hi Mikel,

Thank you for writing.

The visual element to which you are setting the image in the ItemFormatting event is actually a container of the text and value elements. The visual element also does not have a text and an image set to it will always be positioned in the center of the element. The text which is displayed comes from the child text and value elements. I can suggest accessing any of these child elements and applying the image. You can also control how the image is positioned in relation to the text with the TextImageRelation property: 
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    Image image;
    public RadForm1()
    {
        InitializeComponent();
 
        new RadControlSpyForm().Show();
 
        this.image = Image.FromFile(@"..\..\error.png");
        this.radPropertyGrid1.SelectedObject = this;
        this.radPropertyGrid1.ItemFormatting += RadPropertyGrid1_ItemFormatting;
    }
 
    private void RadPropertyGrid1_ItemFormatting(object sender, Telerik.WinControls.UI.PropertyGridItemFormattingEventArgs e)
    {
        PropertyGridTextElement textElement = e.VisualElement.FindDescendant<PropertyGridTextElement>();
        if (textElement == null)
        {
            return;
        }
 
        PropertyGridItem item = e.Item as PropertyGridItem;
        if (item != null && item.Value != null && item.Value.ToString() == "RadForm1")
        {
            textElement.Image = this.image;
            textElement.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage;
        }
        else
        {
            textElement.ResetValue(LightVisualElement.ImageProperty, Telerik.WinControls.ValueResetFlags.Local);
            textElement.ResetValue(LightVisualElement.TextImageRelationProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }
}

I am also attaching a screenshot showing the result on my end. I hope this will help.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
MaiK
Top achievements
Rank 1
answered on 15 May 2018, 03:49 PM
That worked! Thank you.
Tags
PropertyGrid
Asked by
MaiK
Top achievements
Rank 1
Answers by
Hristo
Telerik team
MaiK
Top achievements
Rank 1
Share this question
or