|
You already asked this in QA. Please do not cross post.
|
|
|
|
|
Generating a random colour is easy,
Color.FromArgb(random.Next() | ~0x00FFFFFF)
~0x00FFFFFF is a trick to write unchecked((int)0xFF000000), and the bitwise OR with that value sets the Alpha component to 255 (ie, fully opaque).
It's the "most random" way to generate a colour, that is, each of the 16777216 opaque colours is generated with equal probability. Unfortunately, most of those colours look like poo.
The solution is to generate a random colour in HSV space,
Color.FromArgb(HSV2RGB(random.NextDouble(), 1, 1))
static int HSV2RGB(double h, double s, double v)
{
int h_i = (int)(h * 6);
double f = h * 6 - h_i;
double p = v * (1 - s);
double q = v * (1 - f * s);
double t = v * (1 - (1 - f) * s);
double r, g, b;
switch (h_i)
{
default:
r = v; g = t; b = p;
break;
case 1:
r = q; g = v; b = p;
break;
case 2:
r = p; g = v; b = t;
break;
case 3:
r = p; g = q; b = v;
break;
case 4:
r = t; g = p; b = v;
break;
case 5:
r = v; g = p; b = q;
break;
}
return (-0x01000000 | ((int)(255 * r) << 16)) | (((int)(255 * g) << 8) | (int)(255 * b));
}
-0x01000000 is yet an other trick to write unchecked((int)0xFF000000).
When generating multiple colours, this method still sort of fails: it will produce clashing colours. To avoid that, start with a random colour and add a specific offset
double h_colour = random.NextDouble();
for (int i = 0; i < colours.Length; i++)
{
colours[i] = Color.FromArgb(HSV2RGB(h_colour, 1, 1));
h_colour = (h_colour + 0.618033988749895) % 1;
}
modified 15-Jul-13 14:28pm.
|
|
|
|
|
harold aptroot wrote: ~0x000000FF ~0x00FFFFFF is a trick to write unchecked((int)0xFF000000)
FTFY
(~0x000000FF gives 0xFFFFFF00)
|
|
|
|
|
I can actually not believe I did that. WTF. It's on the level of 1+1=3.
|
|
|
|
|
Sounds like homework to me but here's a couple of clues:
Random myRandom = new Random();
int randomNumber = myRandom.Next(101);
Now, how could I take my randomNumber and select a colour based on that value..?
Perhaps you could do a little research into system.drawing.color?
Then I need to do something like the code below to change the background colour...
this.BackColor = System.Drawing.Color.Red;
|
|
|
|
|
when I add a data Source to Combo Box but when I Run program I get an err :
'O:\C#\School\School\School\bin\Debug\bin\Debug\TabrizKarDB.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
if U get it , there is two of this : \bin\Debug\bin\Debug\
but in Directory I have One !!!!
why i get that err ?
|
|
|
|
|
Because you mistyped the path somewhere??
There's no way for us to tell you what the problem is because we can't see your code, your screen, your hard drive contents, or read your mind!
You have to show us the code here, inside HTML PRE tags, for us to tell you what went wrong.
|
|
|
|
|
I need to instatiate a dictionary accepting null as value, but I have a syntax problem:
Dictionary<string, double[]?> d = new Dictionary<string, double[]?>()
d.Add("a", new double[2]{100,102});
d.Add("b", null);
d.Add("v", new double[2] { 99, 101 });;
Is it possible to do it?
|
|
|
|
|
What happens when you try?
Use the best guess
|
|
|
|
|
You don't need the '?' at all - you need that to specify a value type that can hold a null value. Reference types automatically can (as this is the default value for a reference type variable)
All arrays are reference types, regardless of whether they are array of reference or value types. So what you need to say is:
Dictionary<string, double[]> d = new Dictionary<string, double[]>();
d.Add("a", new double[2] { 100, 102 });
d.Add("b", null);
d.Add("v", new double[2] { 99, 101 });
You would only need the '?' if you wanted an array of doubles that could hold null values, and then the syntax would be:
double?[] da = new double?[10]; To indicate that the individual elements of the array could contain nulls.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Thanks in this way I'm not able to find the Max value of first element
var ks = d.Max(v => v.Value[0]);
I didn't clarify before this port sorry
|
|
|
|
|
Then all you need to do is change the lambda expression to allow for the null value:
var ks = d.Max(v => v.Value == null ? 0.0 : v.Value[0]);
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
thanks in this case I see you need a "hard coded" value 0.0. Is it possible to say "if null just skip it"?
|
|
|
|
|
No, there is no way to "miss out" a value in a IEnumerable iteration.
You could use double.MinValue instead:
var ks = d.Max(v => v.Value == null ? double.MinValue : v.Value[0]);
or
var ks = d.Max(v => { if (v.Value == null) return null; return v.Value[0]; });
But then you need to check for null in the ks variable as a list with all nulls with return a null instead of a double value.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
OriginalGriff wrote: No, there is no way to "miss out" a value in a IEnumerable iteration. Ahem![^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hadn't thought of Where - good point!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
You can use the Where method[^] to skip the null items:
var ks = d.Where(v => v.Value != null).Max(v => v.Value[0]);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
use like this
Dictionary<string, Nullable<double>[]> d = new Dictionary<string, Nullable<double>[]>();
d.Add("a", new Nullable<double>[2] { 100, 102 });
d.Add("b", null);
d.Add("v", new Nullable<double>[2] { 99, 101 }); ;
It would help you.
|
|
|
|
|
I am revisiting a project that I have wanted to do for a long time. I am trying to read Minidumps much like BlueScreenView just with C# code. I was pointed to using
[DllImport("dbghelp.dll", SetLastError = true)]
public static extern bool MiniDumpReadDumpStream(IntPtr BaseOfDump,
int StreamNumber,
ref MINIDUMP_DIRECTORY Dir,
ref IntPtr StreamPointer,
ref UInt32 StreamSize);
And after much digging, I found this
http://www.symbolsource.org/Public/Metadata/NuGet/Project/Microsoft.Samples.Debugging.CorApi/1.4.0.0/Release/Default/Microsoft.Samples.Debugging.Native/Microsoft.Samples.Debugging.Native/DumpReader.cs[ ]
But I am having an issue with being able to pass in a string to the DumpReader and then read the return value. It appears that I need to pass a targetaddress and the length to the ReadMemory but I am getting an exception. I am very new to the whole native code thing. I like my .Net Libraries.
From DumpReader.CS
public byte[] ReadMemory(ulong targetAddress, int length)
{
byte[] buffer = new byte[length];
ReadMemory(targetAddress, buffer);
return buffer;
}
From My Code:
DumpReader dr = new DumpReader(PathToDump);
dr.ReadMemory(??, ??);
|
|
|
|
|
There's an easier example here[^]. I've got it working using the 4.0 runtime, seems the VS-IDE doesn't read them that well for the 2.0 runtime.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I see that the link in your post describes how to create a MiniDump but what I am looking to be able to do is read them. I am not interested in reading them in VS but through code like BlueScreenView
|
|
|
|
|
Zach.Saunders wrote: I am not interested in reading them in VS but through code like BlueScreenView
And yet you ask the question in a C# forum!
What do you mean by code like BlueScreenView.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I would like to be able to open up the .dmp files programmatically in a C# application and read the output to a form. I am trying to literally make a program that behaves just like Nirsoft's BlueScreenView.
|
|
|
|
|
Zach.Saunders wrote: I would like to be able to open up the .dmp files programmatically in a C# application and read the output to a form. Here's[^] the file format for a Windows CE 5 structure to give an idea how it looks. I don't know where the one for Windows 7/8 is, or even if it's publicly available.
You'd have to research that
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I noticed within the past week or two my latest builds of a specific project are not showing up in Add/Remove programs.
I am using Visual Studio 2010, Windows 7 64 bit (though I've also tried 2 32 bit machines). All latest service packs and updates are installed. The solution is made up of several projects with various references. The Setup and Deployment project is not the Install Shield version, but the built in Microsoft project.
Previous versions of the software installed fine, and still do... but if I pull down a tagged earlier version from CVS, and rebuild the installer for those versions, they do not work either.
I've opened the MSI in Orca, and I can see that the ARPNOREMOVE, ARPSYSTEMCOMPONENT are both set to 1. When the project gets installed, a registry entry SystemComponent Dword value is created. If I remove that registry entry, the application shows up. Based on everything I've read and researched I have found people that WANTED this funcitonality but were told Visual Studio can not do this on its own and their solutions were to use Orca to add the ARPNOREMOVE or ARPSYSTEMCOMPONENT. At this point, all of the people who had my problem that I can find either had a basic default installer and they didn't know what name they were looking for in Add/Remove Programs or some other basic error that doesn't apply in my situation.
I've tried all of the following.
-Previous versions of tagged versions on CVS
-Multiple development machines
-Multiple computers to verify none show up in Add/Remove programs -Resetting all Visual Studio settings
-Building from a clean development environment
-Removing Installer project from the solution and creating a new installer project
The weird part is that if I create a new solution and just create a setup and deployment project within, that installs fine.
|
|
|
|