awesome-inc / FontAwesome.Sharp

A library for using Font Awesome in WPF & Windows Forms applications
Apache License 2.0
384 stars 89 forks source link

Icons is not always shown. #65

Closed dubstab96 closed 3 years ago

dubstab96 commented 3 years ago

I have a WinForms application that i am building with C# and sometimes the icons is not showing at all. After an app restart maybe they will.

mkoertgen commented 3 years ago

Hi @dubstab96 ,

Thanks for reaching out. Can you provide some more context, e.g. what specific icons and with what controls you use them?

dubstab96 commented 3 years ago

Im using mostly IconButton and IconPictureBox in my application. Sometimes there are no icons showing, sometimes some shows and some others not and sometimes everything works just fine. Here are some screenshots of different runs.

Successfull run: image

Not successfull run: image

I don't know if this is kind of VStudio Debugger problem, seems to happens on builded app also. I might have to mention that i also use MaterialSkin controls (https://github.com/IgnaceMaes/MaterialSkin) and in one on thousands an exeption will occur on startup, stating that "Roboto" font does not support style "Regular".

mkoertgen commented 3 years ago

Looks cool! There were some recent fixes regarding WinForms font selection, e.g. by explicitly setting the FontStyle, cf.:

Not sure what NuGet-version you are using.

dubstab96 commented 3 years ago

Im using FontAwesome.Sharp version 5.15.3 Seems to be the latest.

mkoertgen commented 3 years ago

Ok, did you tree setting the FontStyle explicitly?

dubstab96 commented 3 years ago

Yes, just found out that it was set to Auto. I will set every control with the right IconFont and i will let you know if the problem is solved :) Thank you very much

dubstab96 commented 3 years ago

After setting the IconFont property of some of the controls an ArgumentNullExeption was thrown image

Again this exeption is not thrown every time application start. After two retries the app started just fine.

mkoertgen commented 3 years ago

Ok, this looks like a problem with initialization order, i.e. fonts are not yet fully loaded. The IconFont-setter should be this line, cf.:

Could you provide the whole stack-trace here?

dubstab96 commented 3 years ago

i'm not sure if this is what you need. System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. Parameter name: family Source=System.Drawing StackTrace: at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont) at System.Drawing.Font..ctor(FontFamily family, Single emSize, GraphicsUnit unit) at FontAwesome.Sharp.FormsIconHelper.GetAdjustedIconFont(Graphics g, FontFamily fontFamily, String text, SizeF size, Int32 maxFontSize, Int32 minFontSize, Boolean smallestOnFail) at FontAwesome.Sharp.FormsIconHelper.ToBitmap[TEnum](FontFamily fontFamily, TEnum icon, Int32 width, Int32 height, Nullable1 color, Double rotation, FlipOrientation flip) at FontAwesome.Sharp.IconButton`1.UpdateImage() at FontAwesome.Sharp.IconButton.set_IconFont(IconFont value) at RPA_Client.Forms.Assistant.InitializeComponent() in C:\Users\badil\Documents\Visual Studio 2019\Projects\RPA_Client\RPA_Client\Forms\Assistant.Designer.cs:line 95 at RPA_Client.Forms.Assistant..ctor() in C:\Users\badil\Documents\Visual Studio 2019\Projects\RPA_Client\RPA_Client\Forms\Assistant.cs:line 30 at RPA_Client.LoginForm.LoggedIn(Object sender, EventArgs e) in C:\Users\badil\Documents\Visual Studio 2019\Projects\RPA_Client\RPA_Client\Forms\LoginForm.cs:line 64 at RPA_Client.Api.d__46.MoveNext() in C:\Users\badil\Documents\Visual Studio 2019\Projects\RPA_Client\RPA_Client\Models\Api.cs:line 77

This exception was originally thrown at this call stack: [External Code] RPA_Client.Forms.Assistant.InitializeComponent() in Assistant.Designer.cs RPA_Client.Forms.Assistant.Assistant() in Assistant.cs RPA_Client.LoginForm.LoggedIn(object, System.EventArgs) in LoginForm.cs RPA_Client.Api.Login(RPA_Client.Models.LoginUserCredentials) in Api.cs`

mkoertgen commented 3 years ago

Looks like this line here, cf.:

Yes, this should help.

Just for completeness: Which .NET/Core- and OS-version are you using?

Will also check for possible side-effects with https://github.com/IgnaceMaes/MaterialSkin

Not sure when i can promise you feedback on this.

Would you be able or willing to submit a pull request?

dubstab96 commented 3 years ago

I am using .NET Version 4.8.04084 Windows 10 build 19042.867

I am sorry but this project is taking the 110% out of me. Maybe some time in the future :)

Thank you for your help, Always happy to hear from you.

mkoertgen commented 3 years ago

Ok, no problem. Target system is the same i guess, i.e Win10, net48?

dubstab96 commented 3 years ago

Yes, I tried to remove completely every reference of the MaterialSkin and after two whole days, no problem occured. Everything works just fine. Seems that there are side effects when MaterialSkin and Fontawesome.Sharp is loaded

mkoertgen commented 3 years ago

Hi @dubstab96, ok for you to close the issue then?

dubstab96 commented 3 years ago

Of course. Thank you very much for your help