Center icon in floating window

1 Answer 49 Views
Form
Carlos
Top achievements
Rank 1
Carlos asked on 18 Jan 2024, 07:12 PM

Hi,

I am adding a custom icon into a floating docking window using this code:

    private void SetHeaderIcon(ToolWindow toolWindow, Icon icon)
    {
      toolWindow.FloatingParent.Icon = icon;
      toolWindow.FloatingParent.ShowIcon = icon != null;
      toolWindow.FloatingParent.FormElement.TitleBar.IconPrimitive.Visibility = icon != null ? ElementVisibility.Visible : ElementVisibility.Collapsed;
    }

The icon is added correctly, but it's not centered. I don't know if it's a problem of the theme, or it's just expected behaviour.

I added 2 screenshots of what I see with a custom icon, and with the default icon.

Is there a way to add margins or center it?

I'm using Telerik for WinForms 2018.3.911.40

Thank you.

1 Answer, 1 is accepted

Sort by
0
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 22 Jan 2024, 09:04 AM

 Hello, Carlos,

Thank you for the provided pictures.

Indeed, this is not expected behavior. I suppose it a theme specific problem. Is it possible to share which is the exact theme which you use in your project? I have tested the floating window on my side with the Fluent theme and the custom icon is shown centered in the title bar:

You can set ImageLayout property of IconPrimitive to Center. In addition, you can try adjusting the Padding property in order to center the icon properly.

this.toolWindow1.FloatingParent.FormElement.TitleBar.IconPrimitive.ImageLayout = ImageLayout.Center;

In case you have furhter difficulties it would be of geat help if you can specify the theme name, so I can test the theme on my side as well.

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

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Carlos
Top achievements
Rank 1
commented on 22 Jan 2024, 10:02 PM

Thank you for the answer,

I validated if the image was centered and it was already. I also validated with a clean app and it worked for me as well, so had to be the theme. After having a look at all the properties of the icon primitive, and comparing them to the clean app without any theme loaded, i found that the margin was set to 0 in my theme.

In code I could fix it with:

toolWindow.FloatingParent.FormElement.TitleBar.IconPrimitive.Margin = new Padding(5, 5, 0, 0);

which is the default margin.

I changed the theme and also worked as expected.

Thank you for your help.

Nadya | Tech Support Engineer
Telerik team
commented on 23 Jan 2024, 01:08 PM

Hello, Carlos,

I am glad to hear that you managed to fix the default margin in the title bar. Thank you for sharing this here with the community.

In case you have any other questions do not hesitate to contact me.

Tags
Form
Asked by
Carlos
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or