|
No. I would call it a "special feature".
conclusion: sh*t happens
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
There is most definitely a bug in the .Net framework, as explained by Paulo Santos[^]. Sorry if the link breaks later, but it only seems to have survived in the Google cache.
The short of it is that the Icon class calls the Win API function CreateIconFromResourceEx to extract the appropriately sized image from the .ico file with the wrong parameters, resulting in it always loading the closest match to a 32x32 image it can find. Paulo does explain a way to force it to load a 256x256 vista icon image, however he also discovered that .png images incorrectly register their size in the .ico file as 0x0 pixels.
So, with only one .png in the .ico file it will always be loaded, but the size recorded in the Icon object will never match. Consequently a subsequent call to Icon.ToBitMap will attempt to re-load the wrong size image from the .ico file and will promptly crash with an ArgumentOutOfRangeException !
The solution is, don't use .png images in icons. Or if you do then make sure you also include a 32x32 pixel .bmp image.
Alternatively, wait for a bug fix from Microsoft, but don't hold your breath.
|
|
|
|
|
Excellent answer!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Thank you very much for your detailed answer!
In fact, I've already found the workaround like this.
Bitmap bmp;
using (var ms = new MemoryStream())
{
icon.Save(ms);
bmp = (Bitmap)Image.FromStream(ms);
}
Now, I'm rewriting my poor article and dirty code. I will put it in my code.
|
|
|
|
|
Your welcome.
The Paulo link I posted claimed to have an replacement Icon class, but I couldn't download it. Shame really, as I bet it would have been stuffed with goodies relevant to your article.
|
|
|
|
|
I am working on an application where I have created a class emp which has ID and Name as a property. Now I want to create a collection of Emp class , which should be sorted based on the either ID or Name. (Program will decide whether it want to data sorted based on the Name or Id at the runtime). For and employ ID and NAMe property is not unique. It is possible that employed is having similar name.
Can you please help me to decide which .net collection object should be used to achieve above functionality?
If possible please provide a snippet.
public class Emp
{
private int myID;
public int ID
{
get { return myID; }
set { myID = value; }
}
private string myName;
public string Name
{
get { return myName; }
set { myName = value; }
}
}
|
|
|
|
|
Have a look at the SortedList .
My signature "sucks" today
|
|
|
|
|
SortList require a unique key value and in our case name can be duplicate.
|
|
|
|
|
There are two ways to go:
- you could use a collection that sorts itself everytime you add/remove an item; those are pretty good if the sorting criterium is constant.
- you could use any collection that fits your app, then sort it if and when you need it sorted; you can specify the sort criterium dynamically. This article[^] deals with the subject.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I guess you meant:
-you could use a collection that sorts itself everytime you add/remove an item;
|
|
|
|
|
yes, that would be good.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Possible solution.
public class Emp
{
private int myID;
public int ID
{
get { return myID; }
set { myID = value; }
}
private string myName;
public string Name
{
get { return myName; }
set { myName = value; }
}
public static List<Emp> GetEmployees()
{
}
}
In calling code use:
var emps = Emp.GetEmployees();
foreach (Emp emp in emps.OrderBy(e => e.Name))
{
Console.WriteLine(emp);
}
foreach (Emp emp in emps.OrderBy(e => e.ID))
{
Console.WriteLine(emp);
}
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Hi,
I have a requirement to produce a grid where the rows are organised as if they were in a FlowLayoutPane set to flow vertically. The grid would been to support editing, colouring, formatting and grouping and all the usual alignment stuff. Full spreadsheet functionality isn't important, but the ability to display ~1000 rows efficiently is.
I'd write the thing myself, except that time is tight and I don't have the inclination to re-invent the wheel .
Does anyone know of anything commercial or free/OS, that would do the job?
|
|
|
|
|
PorkyKat wrote: I'd write the thing myself, except that time is tight
Do you have the time to use google?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
DOH! I never thought of that. Yes, I've tried google. Using 'flow layout' and 'grid' returns a wall of noise about flow layout and grid layout, CSS, but nothing useful to me. Neither did variations on those search terms. I'm happy to admit I may have missed something, but google was my first port of call.
What puzzles me is that you must have tried the search and found something easily, and didn't mention it. After all, you wouldn't have posted that reply to my question *without* doing a google search would you?
|
|
|
|
|
i have 2 windows: mainwindow and feedbackwindow.
there is a button in mainwindow that is supposed to pass the system(is that the right term?) to the feedbackwindow and open it.
but i can't and I'm not sure how.
sorry. I'm a beginner with csharp and i'm not sure if i'm doing something wrong.
i was trying to access another xaml file within the project using the button handler. that's possible right?
public void GenerateForm(...){
FeedbackFormWindow ffw = new FeedbackFormWindow();
ffw.Show();
}
is this wrong?
please help. thank you.
|
|
|
|
|
Are you working with winforms or WPF?
My signature "sucks" today
|
|
|
|
|
|
Hi,
I finished developing the .net windows application.problem is in date format.the application developed with the date format of "MM/dd/yyyy" with this appication working fine.but now i want to change the dateformat to "dd/MM/yyyy" by setting this format im getting the folling error "String was not regcognized as valid date format". i have to change the format in one place so that it gets effect in all over the application.
i have tried withe the below code.but its not working.
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
culture.DateTimeFormat.LongTimePattern = "";
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
Regards
Kanna
|
|
|
|
|
I just wrote a quickie C# WinForms application duplicating your code, and it works fine. Ditto with a console app. Is this an ASP.NET app you are working on?
|
|
|
|
|
No Yaar,that code will convert to desire format.but while inserting the record im geeting the error.string was not recognized as valid datetime. for this what i have to do.
|
|
|
|
|
what sort of database are you using - what is the table/column definition ?
I know Oracle has a function like from_date('18052010', 'ddmmyyyy') type of thing (that may not be exact), that works if the column is defined as date or datetime - ie you can use the 'ddmmyyyy' to tell Oracle how to parse the first argument, in this case 18th 05 (May) in 2010, Non American format
'g'
|
|
|
|
|
Oh, it's a database insert issue. What database are you using? MySQL? If MySQL, try yyyy-MM-dd.
|
|
|
|
|
IM using MS Sql Server 2005 db.
|
|
|
|
|
I think we've established that you're getting an Microsoft SQL Server syntax error on an insert, right? Did you check the actual insert statement string in the debugger?
That date format is valid for MS SQL, and it's fine with a date-only without time for a DATETIME.
At this point without more info (some code), my best guess would be the usual suspects: columns in INSERT statement out of order or a need to quote the fields. Try backquote.
|
|
|
|