Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get icons with Icon.FromResources #2164

Closed
WileyNg opened this issue Mar 15, 2022 · 4 comments
Closed

Cannot get icons with Icon.FromResources #2164

WileyNg opened this issue Mar 15, 2022 · 4 comments

Comments

@WileyNg
Copy link

WileyNg commented Mar 15, 2022

Expected Behavior

Getting the icons with Icon.FromResources

Actual Behavior

image
image

Error
System.ArgumentException: 'Resource 'Terrain.Resources.Terrain.png' not found in assembly 'Terrain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
Parameter name: resourceName'

Steps to Reproduce the Problem

  1. Import Eto.dll (2.6)
  2. Eto.Drawing.Icon SculptIcon_icon = Eto.Drawing.Icon.FromResource("Terrain.Resources.Terrain.png");

Code that Demonstrates the Problem

Eto.Drawing.Icon SculptIcon_icon = Eto.Drawing.Icon.FromResource("Terrain.Resources.Terrain.png");

Specifications

  • Version: 2.6
  • Platform(s):
  • Operating System(s):
@cwensley
Copy link
Member

The Icon/Image must be an Embedded Resource. In your csproj, something like this is usually helpful:

<EmbeddedResource Include="Resources\**\*.*" />

Hope this helps.

@WileyNg
Copy link
Author

WileyNg commented Mar 15, 2022

Big Thanks! You saved me hours of research time!

image

I also wonder how I can align the text in TabControl --> TabPage to middle?
Right now it looks weird having the Text aligning to the Top.

TabControl didn't have such exposed properties..

Also how do I change the text font for the TabPage.Text?

@WileyNg
Copy link
Author

WileyNg commented Mar 15, 2022

After asking a while, I am assuming Eto has limits and these unexposed properties cannot be changed?

@cwensley
Copy link
Member

cwensley commented Apr 24, 2022

For properties that aren't exposed, or platform-specific functionality you can use native styles. E.g. this would fix it for you:

myTabControl.Styles.Add<Eto.Wpf.Forms.Controls.TabPageHandler>(null, h =>
{
	if (h.Control.Header is System.Windows.Controls.StackPanel stackPanel)
	{
		var textBlock = stackPanel.Children.OfType<System.Windows.Controls.TextBlock>().FirstOrDefault();
		if (textBlock != null)
		{
			textBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center;
		}
	}
});

That being said, I think having it centred by default would make sense so I've added #2197 to get that fixed up.

Do note that other platforms may limit the logical size of the icon to 16x16 (e.g. MacOS, WinForms).

Closing this issue as it has been answered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants