I am using VS-C# and have created an embedded resource for images and Icons. I am able to get the icon to display in the dialog but I was wondering if my approach can be improved. I have been:
- Using resource manager to pull the icon out of the resource
- Using a method to convert from Icon to memory stream
- Using Eto.Drawing.Icon to convert the memory stream to a Eto Icon
- Then using this result as the Icon for the dialog
Does Eto have a method that will do this internally with out going through this conversion?
Any help would be appreciated:
Best;
Steve
ps: tried this but it does not connected to an embedded resource for me:
dlg.Icon = Icon.FromRecource("Heart.ico")
The Dialog:
internal class MainDialog : Dialog
{
public string Selected { private set; get; }
public MainDialog()
{
DisplayMode = DialogDisplayMode.Attached;
Resizable = true;
Padding = 3;
}
public void ListBoxDialog()
{
ListBox listBox = new ListBox()
{
ID = "lbListBox"
};
listBox.SelectedKeyChanged += (sender, args) => ListBox_OnClkick(sender, args);
var layout = new DynamicLayout
{
ID = "ListBoxLayout",
};
layout.AddRow(new TableLayout()
{
Style = "table-layout-style",
Rows =
{
new TableRow(listBox) {ScaleHeight = false}
}
}
);
Content = new Scrollable();
Content = layout;
}
private void ListBox_OnClkick(object sender, EventArgs args)
{
ListBox lb = (ListBox) sender;
Selected = lb.SelectedValue.ToString();
Close();
}
}
The Implementation:
using (MainDialog mainDialog = new View.MainDialog())
{
///It seams you need to create an Eto Icon from a memory stream
///Does Eto have a method to go from System.Drawing.Icon to Eto.Drawing.Icon?
MemoryStream memoryStream = new MemoryStream();
memoryStream = Singleton.IconToStream((System.Drawing.Icon) Resources.ResourceManager.GetObject("SimpleListIcon"));
Eto.Drawing.Icon etoIcon = new Eto.Drawing.Icon(memoryStream);
mainDialog.Icon = etoIcon;
mainDialog.Size = new Size(300, 500);
mainDialog.Title = "Page Size";
mainDialog.ListBoxDialog();
ListBox lb = (ListBox)mainDialog.Children.First(i => i.ID == "lbListBox");
lb.DataStore = documentList;
mainDialog.Visible = true;
mainDialog.ShowModal();
if (mainDialog.Selected == null)
{
_msg = $"Page size was not selected.";
_note = new SlException(Level.Information, 383, _msg);
break;
}
_docString.SlPageViewSize = mainDialog.Selected;
_docString.SlPageView = pageViewString;
_msg = $"Page view {pageViewString} with a size of '{slPageViewSizeString}' will be created.";
_note = new SlException(Level.Information, 389, _msg);
break;
}
System.Drawing.Icon to Memory stream:
public static MemoryStream IconToStream(System.Drawing.Icon icon)
{
MemoryStream memoryStream = new MemoryStream();
icon.Save(memoryStream);
return memoryStream;
}