|
You might want to think about doing something like this:
Byte b = 200;
if(b < (int)SByte.MaxValue)
{
SByte sb = (SByte)b;
Console.WriteLine(sb);
}
else
{
Console.WriteLine("b is too large.");
}
Essentially you get caught in what I like to think of as a loop, but it isn't. When you go beyond the max (i.e. - MaxValue + 1; ) it will then wrap to the largest negative value. The -55 is correct, it is out of bounds and that's what it is trying to show you. I know you can do checked{...} and unchecked{...} blocks with certain data types which will allow you to control whether or not an exception is thrown, you may or may not be able to use this here.
HTH
Nick Parker
|
|
|
|
|
|
Section 6.2.1 of the C# spec covers this. Basically, the high bits are thrown away, and then the result is sign-extended to get the resultant value. I don't think you'd ever want to depend on this behavior, however.
You can trap such overflow by putting the code in a checked block:
checked
{
byte b = 200;
sbyte sb = (sbyte) b;
System.Console.WriteLine(sb);
}
|
|
|
|
|
|
Does anyone know where I can find a good, accurate algorithm for converting between the RGB and HLS colour models?
I'm writing in C#, but I could probably convert an algorithm from most languages.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Hi,
In the Color class it provides you with methods to convert RGB to HSB (does brightness = lumination ) .
GetHue(): Gets the hue-saturation-brightness (HSB) hue value, in degrees, for this Color structure.
GetSaturation(): Gets the hue-saturation-brightness (HSB) saturation value for this Color structure.
GetBrightness(): Gets the hue-saturation-brightness (HSB) brightness value for this Color structure.
The other way around, i cant help you with, well not yet
HTH
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
OK i found 2 variations:
From Anakrino:
public float GetBrightness() {
float local0;
float local1;
float local2;
float local3;
float local4;
local0 = (float) this.R / 255;
local1 = (float) this.G / 255;
local2 = (float) this.B / 255;
local3 = local0;
local4 = local0;
if (local1 > local3)
local3 = local1;
if (local2 > local3)
local3 = local2;
if (local1 < local4)
local4 = local1;
if (local2 < local4)
local4 = local2;
return local3 + local4 / 2;
}
public float GetHue() {
float local0;
float local1;
float local2;
float local3;
float local4;
float local5;
float local6;
if (this.R == this.G && this.G == this.B)
return 0;
local0 = (float) this.R / 255;
local1 = (float) this.G / 255;
local2 = (float) this.B / 255;
local6 = 0;
local3 = local0;
local4 = local0;
if (local1 > local3)
local3 = local1;
if (local2 > local3)
local3 = local2;
if (local1 < local4)
local4 = local1;
if (local2 < local4)
local4 = local2;
local5 = local3 - local4;
if (local0 == local3)
local6 = local1 - local2 / local5;
else {
if (local1 == local3)
local6 = 2 + local2 - local0 / local5;
else if (local2 == local3)
local6 = 4 + local0 - local1 / local5;
}
local6 = local6 * 60;
if (local6 < 0)
local6 += 360;
return local6;
}
public float GetSaturation() {
float local0;
float local1;
float local2;
float local3;
float local4;
float local5;
float local6;
local0 = (float) this.R / 255;
local1 = (float) this.G / 255;
local2 = (float) this.B / 255;
local6 = 0;
local3 = local0;
local4 = local0;
if (local1 > local3)
local3 = local1;
if (local2 > local3)
local3 = local2;
if (local1 < local4)
local4 = local1;
if (local2 < local4)
local4 = local2;
if (local3 != local4) {
local5 = local3 + local4 / 2;
if ((double) local5 <= 0.5)
local6 = local3 - local4 / local3 + local4;
else
local6 = local3 - local4 / 2 - local3 - local4;
}
return local6;
}
And from the MONO classes (very nice reference indeed ):
public float GetBrightness (){
return ((float)(r + g + b))/(255*3);
}
public float GetSaturation (){
return (255 - (((float)(r + g +b))/3)*Math.Min(r,Math.Min(g,b)))/255;
}
public float GetHue (){
float top = ((float)(2*r-g-b))/(2*255);
float bottom = (float)Math.Sqrt(((r-g)*(r-g) + (r-b)*(g-b))/255);
return (float)Math.Acos(top/bottom);
}
HTH
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Thanks for the info. I'll look into and see if it helps.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
How do I create a C# control that can run in a web-browser on the client side.
I am working on a project where it has been specified that if it can be done in C# it must be.
I don't fancy having to implement all the interfaces myself - it'll be like going back to the old days of OLE - shudder. I am sure there must be a quicker way embedded in .NET - but I just can't find the wood for the trees.
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsIeSourcing.aspx
|
|
|
|
|
|
thanks - I knew I was missing something - so they altered the object tag to do something clever - do you know what versions of IE that works on?
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Shaun Wilde wrote:
do you know what versions of IE that works on?
I *think* it is version 5.0 and up; of course the .NET runtime still needs to be installed on the client.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I want to be able to create a range of objects using an Eval statement, but the name is not recognized.
I'm creating a C# program using the .NET framework, and the compilers doesn't know what eval means.
I'm trying to use a DataSet to create a bunch of objects using code similar to:
Eval("TreeNode node" + ds.Tables["tableName"].Rows[i]["field1"].ToString() + " = new TreeNode(\"" + ds.Tables["tableName"].Rows[i]["field2"].ToString() + "\")");
But that's not gonna pass it seems.
How can I achieve the desired affect using C# and the .NET Framework?
I'm currently researching the System.Reflection class to see what my options are there. Any help from the outside world would be a great thing =)
--chajadan
aka charlie
|
|
|
|
|
Type t = Type.GetType("System.Windows.Forms.TreeNode");
object[] param = new object[0];
ConstructorInfo[] ci = t.GetConstructors();
object o = ci[0].Invoke
(BindingFlags.CreateInstance,null,param,null);
Be sure to pass param with expected binding for one of the TreeNode constructor (in your case, that's a String object).
|
|
|
|
|
Somewhere in the back of my head I remember seeing a VB.Net to C# converter project, but I have looked everywhere and cant find it again.
Has anyone heard of this?
Any help will be great.
PS: If I am dreaming, writing something like that cant be too hard, I dont know VB/VB.Net but I find converting code manually between VB.Net and C# quite boring, basically C# in reverse and all those pesky Capped keywords.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
There is no VB to C# converter; the reverse exists but I don't have a current pointer.
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
|
I take it back
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Nick Hodapp (MSFT) wrote:
I take it back
hmm, both does the same, but thanx for the replies
Time to start the VB.Net to C# project then
Or maybe one of you MS guys can beat me to it.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
My take on the whole thing is rather use C# from the beginning.
Trolling, sure, but C# has always seemed to have more backing by MS and I hear the only reason why VB hasn't died is that it's Bill's baby.
Cheers,
Simon
"Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
|
|
|
|
|
SimonS wrote:
My take on the whole thing is rather use C# from the beginning.
I agree, but unfortunately there are quite alot of good code being published in VB.Net format
So now i have to manually parse files and change the structure, eg it took me 2 1/2 hours just to convert a 1700 line VB.Net class, excluding loops and other VB specifics, that normally would take just as long.
The thing is, in CLR its all the same. Then you can use Anakrino to view the code. That said, it does crash in some parts (maybe vb specific stuff???)
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
I agree, but unfortunately there are quite alot of good code being published in VB.Net format
That's funny, this is the major reason I was learning C# (because I keep finding alot of good code written there )
|
|
|
|
|
first of all i start a process by process start method
and then i get its parent and then child hwnd but now what want is that
if i have a button hwndle on a processs main window how to
check that this button is clicked or not or any other operation is performed on it or not.
and if i want to generate any mouse event let say mouse click event then how to generate it or any other message?
Remember that i have only the button hwndle do not have its object .
r00d0034@yahoo.com
|
|
|
|
|
Your project looks very much like a non .Net project, full with "hwnd" and so on.
I would recommend to choose a lower-level language such like C++/MFC that looks more adequate.
If you've got to stick with C#, you've got at least two choices :
- use interop, such as the code shown in the other thread
- use MessageQueue, which is a reliable messaging tunnel. I just gave a look and the .Net framrwork QuickStart tutorials are just helpful to start with. MessageQueue will not do everything, you'll have to do plummering between queues and the actual message subscribers/senders.
get to www.dotnet247.com. This server is almost as down as codeproject, but it is full of useful code snippets and revelant answers.
|
|
|
|