How to align Image to the centered text in RadLabel

2 Answers 13 Views
Label
Pawel
Top achievements
Rank 1
Iron
Pawel asked on 17 Apr 2024, 08:10 AM

Hi,

I found how to put into radlabel a image here: https://www.telerik.com/forums/image-for-label and here is my code:

((TextPrimitive)this.lblTitle1.LabelElement.Children[2].Children[1]).Font = new Font("Roboto", 32, FontStyle.Bold);
ImagePrimitive imgPrimitive = new ImagePrimitive();
this.lblTitle1.RootElement.Children[0].Children.Add(imgPrimitive);
imgPrimitive.Image = WSResourceManager.UiImageProvider.InfoYellowIcon.Get(WSConfigurationManager.GetInstance.GetLargeIconSize());

Now I would like to align the image to the text that is centered (designer):

but as a result I get this (result):

 

How can I align this icon to the text?

 

2 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 18 Apr 2024, 02:37 PM

Hello, Pawel,

Thank you for the provided information.

You are reffering to quite an old forum post. If you want to assign an image in RadLabel you should just set the Image property to desired image. Then, you can specify the TextImageRelation to ImageBeforeText. 

As to the setting Font you can use the LabelText property which gives you directly the TextPrimitive. Thus, the code snippet is simplified and looks like this:

this.radLabel1.LabelElement.LabelText.Font = new Font("Roboto", 32, FontStyle.Bold);
this.radLabel1.Image = Resources.temp;
this.radLabel1.TextImageRelation = TextImageRelation.ImageBeforeText;

I hope this information helps. If you have any other questions do not hesitate to contact me.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Pawel
Top achievements
Rank 1
Iron
commented on 22 Apr 2024, 05:38 AM | edited

Hi Nadya,

Thank you for your answer, but this doesn't meet my requirements, as I expect the image to appear just before the text when the text is centered. Please see the attached project.

Result:

The expected result should look similar to the screenshot:

Thank you

0
Nadya | Tech Support Engineer
Telerik team
answered on 24 Apr 2024, 12:25 PM

Hello, Pawel,

The provided project is greatly appreciated. I receive some build errors when trying to run it because of a missing manifest file. This is why I copied the form files and used them in another project which runs correctly. 

While investigating it, I have noticed that you set the AutoSize property of RadLabel to false. If you leave the AutoSize property with its default value which is true, the label should autosize automatically and the image will be displayed right before the text. Here is the result when AutoSize=true and TextImageRelation.ImageBeforeText:

Another approach, if you want to keep AutoSize = false, is to set the following properties:

this.radLabel1.ImageAlignment = System.Drawing.ContentAlignment.MiddleRight;
this.radLabel1.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.radLabel1.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;

I hope this helps. If you have any other questions, please let me know. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Tags
Label
Asked by
Pawel
Top achievements
Rank 1
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or