|
I create the Icon object using the FromHandle method passing in the HICON of the extracted icon.
And when I check the size of the new Icon object, it reads 32 x 32, which is the same as the size I set for the ImageList.
Maybe the ListView is just bad at displaying icons?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Great idea! I'll try that.
Thanks Richard.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Didn't think it would be necessary to ask: WPF, Windows Forms or UWP?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Windows Forms.
I tried Richard's suggestion of converting the icon to a bitmap before adding it to the ImageList, but that didn't fix the fuzziness.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
This sounds interesting:
Quote: Set the appropriate property—SmallImageList, LargeImageList, or StateImageList—to the existing ImageList component you wish to use.
Display Icons for ListView Control - Windows Forms .NET Framework | Microsoft Docs
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I don't see anything on that page that makes any difference.
Thanks for your taking the time to respond.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Without seeing any code I don't know if this will help. I fixed this problem in VB by converting the icon to a bitmap with the routine below. I also use ExtractIconEx. I found that icon.ToBitmap() loses resolution for some reason. Sorry, you'll have to convert to C#.
''' <summary>
''' Convert Icon to Bitmap with resizing.
''' </summary>
''' <param name="ic"></param>
''' <param name="sz"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function IconToBitmap(ByVal ic As Icon, ByVal sz As Size) As Bitmap
If ic Is Nothing Then Return Nothing
Dim sourceWidth As Integer = ic.Width
Dim sourceHeight As Integer = ic.Height
Dim dPercent As Double = 0
Dim dPercentW As Double = 0
Dim dPercentH As Double = 0
dPercentW = (sz.Width / sourceWidth)
dPercentH = (sz.Height / sourceHeight)
If (dPercentH < dPercentW) Then
dPercent = dPercentH
Else
dPercent = dPercentW
End If
Dim destWidth As Integer = (sourceWidth * dPercent)
Dim destHeight As Integer = (sourceHeight * dPercent)
Dim bm As Bitmap = New Bitmap(destWidth, destHeight, PixelFormat.Format32bppArgb)
bm.SetResolution(destWidth, destHeight)
Dim g As Graphics = Graphics.FromImage(bm)
'g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
' This gives the best quality
g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
g.DrawIcon(ic, New Rectangle(0, 0, destWidth, destHeight))
g.Dispose()
Return bm
End Function
|
|
|
|
|
Wow! Thanks Mr. Bump.
I'll give this a try. I am thankful that you have solved this problem.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I have got some assembly in my sub folder and I know how to load it.
The problem is with other assemblies in this folder that this assembly is depending on.
I'm guessing that application would search for them only in it's own directory when loading assembly and not at assembly location.
Now I know about AppDomain.AssemblyResolve, but how can I subscribe to it in my assembly so I don't have to mess around with it in my main application.
Or how can I load all dependent assemblies when my assembly is loaded.
|
|
|
|
|
koirat wrote: The problem is with other assemblies in this folder that this assembly is depending on. You should indicate exactly what the problem is. Maybe there is a fix.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The problem is that assemblies that my loaded assembly is dependent on are not going to be loaded automatically from directory different than main executable file location.
|
|
|
|
|
I guess you have to ask yourself why you are dynamically loading instead of simply including a reference in the project. DLL hell all over again.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I want to create plugin based system where I can exchange or add new functionality to my application just by putting a bunch of dll into plugin location.
|
|
|
|
|
If you're the only user, seems pointless; if you plan to distribute it, chances are the target environment won't allow it (for whatever reason), or they'll mess up the installation / maintenance.
Windows deals in "packages" once you're out of the wild.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
koirat wrote: Or how can I load all dependent assemblies when my assembly is loaded.
Assembly.GetReferencedAssemblies Method (System.Reflection) | Microsoft Docs[^]
Load those, and their dependencies before loading you assembly. Requires reflection and recursion.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Not good enough I need my assembly to load it's dependencies by itself. I don't want to do anything in my main application except loading particular dll.
Right now I have tried static class with AssemblyResolver event subscribed in constructor but it never gets called.
|
|
|
|
|
koirat wrote: Not good enough I need my assembly to load it's dependencies by itself. It's a programming language; things don't happen by themselves.
MS Access hides complexity; try that.
--edit
It just takes a few lines of code to do it by "itself", and requires actual programming. And I is for sale
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
modified 8-Sep-20 16:54pm.
|
|
|
|
|
Actually they do. I was able to pull it out in the end.
public static class AssemblyResolver
{
public static HashSet<Assembly> SupportedRequestors { get; set; } = new HashSet<Assembly>();
static AssemblyResolver() {
SupportedRequestors.Add(typeof(AssemblyResolver).Assembly);
}
public static void Initialize() {
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) {
if (SupportedRequestors.Contains(args.RequestingAssembly)) {
AssemblyName assemblyName = new AssemblyName(args.Name);
string assemblyPath = Path.Combine(Path.GetDirectoryName(args.RequestingAssembly.Location),assemblyName.Name+".dll");
Assembly loadedAssembly = Assembly.LoadFile(assemblyPath);
SupportedRequestors.Add(loadedAssembly);
return loadedAssembly;
}
return null;
}
}
|
|
|
|
|
I have the following table, i can join this table to others to build a bigger dataset but I only wnat to run one query to get the data and then build a data model shown below. I can build a Single model but i want to do more like a JSON serialization.
Can anybody show me a LINQ or other method that would be efficient and could be expanded to use generics?
Thanks
Madaxe
School Class Student
Bakers 19A Bob
Bakers 19A Jim
Bakers 17A Gary
Bakers 17A Stuart
DataClass
IEnumerable<schoolclass> Schools
SchoolClass
IEnumerable<studentclass> Classes
StudentClass
|
|
|
|
|
I found this one example is this the best method / approach?
<pre>namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
List<Customer> CustomerList = new List<Customer>();
CustomerList.Add(new Customer { ID = 1, Name = "One", GroupID = 1 });
CustomerList.Add(new Customer { ID = 2, Name = "Two", GroupID = 1 });
CustomerList.Add(new Customer { ID = 3, Name = "Three", GroupID = 2 });
CustomerList.Add(new Customer { ID = 4, Name = "Four", GroupID = 1 });
CustomerList.Add(new Customer { ID = 5, Name = "Five", GroupID = 3 });
CustomerList.Add(new Customer { ID = 6, Name = "Six", GroupID = 3 });
IEnumerable<CustomerGrouping> CustomerGroupings = CustomerList.GroupBy(u => u.GroupID)
.Select(group => new CustomerGrouping { GroupID = group.Key, Customers = group.ToList() })
.ToList();
}
}
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
public int GroupID { get; set; }
}
public class CustomerGrouping
{
public int GroupID { get; set; }
public IEnumerable<Customer> Customers { get; set; }
}
|
|
|
|
|
mjeeves wrote: s this the best method / approach It all depends on what you are trying to achieve.
|
|
|
|
|
 here is another example data set, i want to go one more level down and group by username and EventTime, but i don't know how to expand the linq, plus i will have to remove the time stamp from the event dattime
<pre>namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
List<SignInReport> SignInReports = new List<SignInReport>();
SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignIn", EventTime = new DateTime(2020,1,18,6,0,0) });
SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignOut", EventTime = new DateTime(2020, 1, 18, 10, 0, 0) });
SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignIn", EventTime = new DateTime(2020, 1, 18, 11, 30, 0) });
SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignOut", EventTime = new DateTime(2020, 1, 18, 16, 30, 0) });
SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignIn", EventTime = new DateTime(2020, 1, 18, 6, 0, 0) });
SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignOut", EventTime = new DateTime(2020, 1, 18, 15, 30, 0) });
SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignIn", EventTime = new DateTime(2020, 1, 19, 6, 30, 0) });
SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignOut", EventTime = new DateTime(2020, 1, 19, 17, 45, 0) });
IEnumerable<SignInReportGrouping> SignInData = SignInReports.GroupBy(u => u.UserName)
.Select(group => new SignInReportGrouping { UserName = group.Key,
SignInReports = group.ToList() })
.ToList();
}
}
public class SignInReport
{
public string UserName { get; set; }
public string EventName { get; set; }
public DateTime EventTime { get; set; }
}
public class SignInReportGrouping
{
public string UserName { get; set; }
public IEnumerable<SignInReportDay> SignInReportDay { get; set; }
}
public class SignInReportDay
{
public IEnumerable<SignInReport> SignInReports { get; set; }
}
}
|
|
|
|
|
Since you're using Linq-to-Objects, that's simple enough to do:
IEnumerable<SignInReportGrouping> SignInData = SignInReports
.GroupBy(u => u.UserName)
.Select(user => new SignInReportGrouping
{
UserName = user.Key,
SignInReportDay = user
.GroupBy(u => u.EventTime.Date)
.Select(day => new SignInReportDay
{
Day = day.Key,
SignInReports = day.ToList(),
})
.ToList(),
})
.ToList(); You'll probably want to add the Day property to your SignInReportDay class so you know which day it represents:
public class SignInReportDay
{
public DateTime Day { get; set; }
public IEnumerable<SignInReport> SignInReports { get; set; }
}
NB: If you're using Entity Framework 6, you probably won't be able to use the .Date property. For EF6, use DbFunctions.TruncateTime :
.GroupBy(u => DbFunctions.TruncateTime(u.EventTime)) For EF Core, the .Date property should work correctly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have a custom font. The font contains symbols at specific addresses. I want to display one of the symbols in a TextBlock.
The font (ttf-file) is located in my applications's folder: Fonts.
I have included the font in the application and set the BuildAction to Resource .
I have verified the font's name (not file name) to reference it in my code.
I have verified which "address" the symbol should be fetched from in the font.
I have tried this both in XAML and with C#. But it won't work.
XAML
<Window x:Class="Main.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Main"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Style x:Key="Foo">
<Setter Property="TextElement.FontFamily" Value="pack://application:,,,/Main;component/Fonts/#MyFont" />
</Style>
</Window.Resources>
<StackPanel Orientation="Vertical">
<TextBlock Text="&#x E905;" Style="{StaticResource Foo}" />
<TextBlock FontFamily="Segoe MDL2 Assets" Text="&#x E777;" />
<TextBlock x:Name="txt1" />
<TextBlock x:Name="txt2" />
</StackPanel>
</Window> Notice: Never mind the space in the middle of "address" for the first and second TextBlock. The code-view here at CodeProject failes to display the address. It tries, and fails, to fetch the correct symbols by that address - if I remove the space in the addresses...
C#
Here is the handler for the Loaded event :
private void Window_Loaded(object sender, RoutedEventArgs e)
{
txt1.FontFamily = new FontFamily("pack://application:,,,/Main;component/Fonts/#MyFont");
txt1.Text = "\xe905";
txt2.FontFamily = new FontFamily("Segoe MDL2 Assets");
txt2.Text = "\xe7777";
} Result
The result are displayed in the four TextBlocks. From top to bottom:
* First: This fails. I get an empty rectangle, like these rectangles.
* Second: This line works. You should be able to copy this line into your own application with success.
* Third: Same as the first TextBlock. An empty rectangle.
* Forth: This "works". I get the correct symbol as well as an empty rectangle.
What could be the problem?
|
|
|
|
|