|
How do i make an enum, such that when you are assigning a property of that enum, you can specify more that one of the flags, e.g.
someThing.Proprty = AnEnum.Foo | AnEnum.Bar;
and is there something special i have to do to find which ones were specified?
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Use FlagsAttribute
Here is an example:
[Flags]
public enum AA
{
...
}
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
Nnamdi Onyeyiri wrote:
and is there something special i have to do to find which ones were specified?
Yes, unfortunately
1. Flags Enums must be bit settable ie
enum MyEnum {
None = 0x00,
FlagA = 0x01,
FlagB = 0x02,
FlagC = 0x04,
FlagD = 0x08,
FlagE = 0x10,
FlagF = 0x20,
FlagG = 0x40,
FlagH = 0x80
}
2. To get the value (this is my difficult part as bit operations is somethin my mind cant process yet). I use this snippet to view Flags.
public static string PrintFlags(object enumvalue)
{
Type t = enumvalue.GetType();
string output = "";
foreach(string enumName in (string[])Enum.GetNames(t))
{
if ((((int)enumvalue) & (int)Enum.Parse(t, enumName)) != 0)
output += "[" + enumName + "]";
}
return output;
}
To get value is something like (from above):
if ((enumvalue & MyEnum.FlagA) != 0) then flag is set, else not set
Hope this helps I think I have learnt something at least
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
JTJ said i can do this
[Flags]
enum Stuff {
itemA = 1,
itemB = 2,
itemC = 4
}
then to get the ones set, do this
Stuff myStuff = Stuff.itemA | Stuff.itemB;
....
bool hasItemA = (myStuff & Stuff.itemA) == Stuff.itemA;
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
The 1st part I did like that to show the bit formation
Re, the getting part, thats where my math is &^%&^% with my head.
I cant see how :
bool hasItemA = (myStuff & Stuff.itemA) == Stuff.itemA;
bool hasItemA = (myStuff & Stuff.itemA) != 0;
can be the same ??? To me , mine looks correct, I could be wrong.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
& is a bitwise and operator, and works something like this (I'm sure I'll be jumped on if I'm wrong here
Ok, assuming that the myStuff variable contains the bit flags, and exists as:
01001001
Now, assuming that Stuff.itemA is set to 00000001 then performing an AND bitwise operator on the two should yield the following
01001001 +
00000001
---------
00000001
The result will only be 1 where both the parameters are 1, so 1+1=1, 0+1=0, 0+0=0 etc.
Consequently the result ought to be itemA again. As a result, both yours and JTJ's version ought to be correct, since they'll both return a result != 0.
--
Paul
"I need the secure packaging of Jockeys. My boys need a house!"
- Kramer, in "The Chinese Woman" episode of Seinfeld
MS Messenger: paul@oobaloo.co.uk
Sonork: 100.22446
|
|
|
|
|
Thanx Paul, nice explanation. I will look at it a bit more to remember it
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
i want to move mouse curser programatically and want to get any key pressed how to do that in csharp like the hooks in vc++ ?
r00d0034@yahoo.com
|
|
|
|
|
I know that the keystroke program can be done:
http://www.c-sharpcorner.com/Code/2002/July/LeyLoggerApp.asp[^]
However, I don't know about moving the mouse. Sorry about that. Hope the keystroke thing was of some help.
David Stone
It seemed similar to someone saying, "Would you like to meet my knife collection?"
Ryan Johnston on Elaine's sig
|
|
|
|
|
is it possible to call any MFC Dialog in csharp code if yes plz tell how ?
r00d0034@yahoo.com
|
|
|
|
|
Why not just design your own? VS.NET has a cool dialog editor as part of the resource editor.
David Stone
It seemed similar to someone saying, "Would you like to meet my knife collection?"
Ryan Johnston on Elaine's sig
|
|
|
|
|
plz help me a little u just design it for me i will launch it with my name.
r00d0034@yahoo.com
|
|
|
|
|
Resource files need to be imbedded into your solution. That means that I can't create it without your solution files.
David Stone
It seemed similar to someone saying, "Would you like to meet my knife collection?"
Ryan Johnston on Elaine's sig
|
|
|
|
|
|
Nope. It's a .rc file and the documentation said that it's tied to the solution. Besides, I don't know what he would want the dialog to look like.
David Stone
It seemed similar to someone saying, "Would you like to meet my knife collection?"
Ryan Johnston on Elaine's sig
|
|
|
|
|
plz you do some help for me.i will be very thank full to you.
plz reply in detail so that i could got some thing out of that.i tried it but could not get any success yet.
provide the related linkes for that if u could provide?
r00d0034@yahoo.com
|
|
|
|
|
|
u mean in msdn
your link did not work.
BUT i find some material in msdn but it seems related to vc++ not vc.net.
what to do?
r00d0034@yahoo.com
|
|
|
|
|
It's OK. You can just open up your C# dll and then edit the resources. If you copy and paste that link into the web browser in VS.NET, then you can go directly to the help file that I meant.
David Stone
It seemed similar to someone saying, "Would you like to meet my knife collection?"
Ryan Johnston on Elaine's sig
|
|
|
|
|
plzzzz ans in detail so that
i could got some thing out of that.
provide some links if u could provide?
or develop a little application and send it to me so that i could understand ?
r00d0034@yahoo.com
|
|
|
|
|
Hi all!!!
Problems....i hate programming problems....why VS .NET tells me that Tcp type namespace doesn't exist in System.Runtime.Remoting.Channels?? (i've put using System.Runtime.Remoting.Channels and System.Runtime.Remoting.Channels.Tcp and i never had good results....why?)
---
((.)) The Vortex ((.))
|
|
|
|
|
Have you added a reference to System.Runtime.Remoting.dll?
I assume you are trying to use a class out of the System.Runtime.Remoting.Channels.Tcp namespace (such as TcpChannel).
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Ive been all over for this one. Im trying to use TraceHook.NET from www.razersoft.net/TraceHook.htm , but there are so many limitations and it seems to have been written using beta code.
The functions its using all have this disclaimer in their help:
The IContextProperty type supports the .NET Framework infrastructure and is not intended to be used directly from your code.
So the code works fine, but all objects MUST inherit from System.ContextBoundObject -- which is an object, not an interface... so I can't put this on forms or anything else that inherits from a class.
Has anyone worked with this thing recently or been able to modify it to a more usable tool? or can someone explain how this thing even works? Ive got the jist, but im still fuzzy on how it ties together. Of course there is no documentation, so im SOL there.
and i have tried to contact the writer with no luck.
thanks
|
|
|
|
|
hi,
i've searched the graphics-class, but i didn't found how to draw a single point.
when i use g.DrawLine(pen,x,y,x+1,y); i get the two pixels connected.
when i use g.DrawLine(pen,x,y,x,y); i get nothing.
any idea?
:wq
|
|
|
|
|
I would suggest to spit on screen so you would get points on screens
More seriously, there is no DrawPoint method available.
MS recommends to use GDI (Marshalled) which is still available.
Or, if performance is an issue, go unmanaged, lock a ptr on a surface and start playing with it.
Now AFAIK, I would recommend a simple to use FillEllipse(x,y,1*nZoomFactor,1*nZoomFactor) where nZoomFactor=1.
And I swallow a small raisin.
|
|
|
|