|
Hi,
have a look at Enum.GetValues() !
PS: It is wise to add the [Flags] attribute if your enum contains only flags
|
|
|
|
|
No, dont want all values of the enum .....i just want the enum-values of the variable.
Scott Dorman understood it right
|
|
|
|
|
You can "cheat" as long as the enum is decorated with the Flags attribute by using the following code:
SampleEnum var = SampleEnum.Alpha | SampleEnum.Gamma | SampleEnum.Epsilon;
string[] varArray = var.ToString().Split("|"); This will give you a string array containing the three enum values as a string. You could then turn each string value back to it's enum value by using Enum.Parse .
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
hmm thanks, i thought about that solution already but i hoped that there are an better way to do this.....
At least i could write a methode that returns an array with the values like this:
public static Enum[] GetArrayFromFlagEnumValue( Enum flagEnumValue ) {
Type flagEnumType = flagEnumValue.GetType();
object[] attributes = flagEnumType.GetCustomAttributes( typeof( FlagsAttribute ), false );
if( attributes.Length > 0 ) {
List<Enum> enumValueArray = new List<Enum>();
int flagEnumIntValue = Convert.ToInt32( flagEnumValue );
int tmpEnumIntValue = new int();
Array reversedEnumValues = Enum.GetValues( flagEnumType );
Array.Reverse( reversedEnumValues );
foreach( Enum enumValue in reversedEnumValues ) {
tmpEnumIntValue = Convert.ToInt32( enumValue );
if( ( flagEnumIntValue - tmpEnumIntValue ) >= 0 ) {
flagEnumIntValue = flagEnumIntValue - tmpEnumIntValue;
enumValueArray.Add( enumValue );
}
}
enumValueArray.Reverse();
return enumValueArray.ToArray();
}
else {
throw new ArgumentException( "The enumation of this value is not marked with the required FlagsAttribute!", "Enum value" );
}
}
</code>
|
|
|
|
|
Hi, i have a problem here, i want to add items to an arraylist that is public in a form
im creating some threads so i try to add items to it from the threads but it doesnt work have a ny idea why.
I already resolve one prob similar but i cant find the asw to this, this prob was that i want to access a listbox from the thread, and what i do was this:
delegate void SetTextCallback(ArrayList text);
private void SetText(ArrayList text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
try
{
if (this.Boxestado.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
for (int i = 0; i <= id.Count; i++)
{
this.Boxestado.Items.Add(text[i]);
}
}
hilo.Abort();
}
catch(Exception)
{
}
}
im trying to understand that it might be a metodh or a safe way to acces object that are running in other methods but with the arraylist i cant figureout this is the code for the thread
public void identificacion()
{
// Se crea un nuevo objeto de la clase Socket_ Server
// se genera el estado escuchar y se espera hasta que algun
// cliente responda
Socket_Server identificacion;
identificacion = new Socket_Server();
id = identificacion.Begin(ip, puerto);
this.SetText(id);
//HERE IS where I WANT TO ADD items from the id wich is a ArrayList to another Arraylis Cln
//so THAT way every time the thread is executed i could be added the items in the id arraylist
// to de Cln, wich its going to have all the items that have been added in some loop.
ejecutar_hilo_identificacion();
}
public void ejecutar_hilo_identificacion()
{
Thread hilo = new Thread(new ThreadStart(identificacion));
hilo.IsBackground = true;
hilo.Start();
}
|
|
|
|
|
Hi,
if you want to manipulate an ArrayList (or anything else for that matter) from
inside multiple threads, then you should give those threads mutual exclusion access
to the ArrayList (so at any point in time at most one thread is manipulating it).
The easiest way is to use the lock keyword.
And yes you are right, you need InvokeRequired and Invoke in order to modify
some Control from any thread that is not the UI thread.
|
|
|
|
|
Hello everyone,
I have a ContextMenu in my Windows Application and I am trying to change it's property but I am unable to do so. For some reason when I change the size of the "Seperator" it goes back to what it was before!!!
Can someone tell me what is going on here and how I can change the size of seperators in my ContextMenu.
Thank you very much and have a great day
Khoramdin
|
|
|
|
|
Hi,
you should be able to draw a menu item yourself, by setting OwnerDraw true, and
providing MeasureItem and DrawItem event handlers.
|
|
|
|
|
Hello Luc,
Thanx for the help. If I am not mistaken base on your suggestion I can customize the entire ContextMenu. That is something which I might consider if there is no other way to get what I am looking for.
The problem is what I am looking for is very simple. I wish to reduce the width of the seperator in the ContextMenu as it overlaps the image that I have placed on the left hand side of the ContextMenu.
Thanx for your help, mate.
Khoramdin
|
|
|
|
|
hi
for change the size property u must first set autosize property to false.
|
|
|
|
|
Hello Maryamf,
Thanx for the reply. That is what I thought initially and believe me when I tell you that I tried it. for some reason the Hight works fine but Width setting is not working. It is fix to what it was picked initially by the Contoller. All I wish to do is to reduce the width of the "Seperator" and align in to the left. Just the way the ContextMenu in Visual Studio is!
Thank you for your help, mate.
Khoramdin
-- modified at 13:23 Sunday 15th April, 2007
|
|
|
|
|
dear all ;
i made an array to save mouse position for 10 seconds and the array contains 10000 elements how can i see all the array elements in text box.
thank you.
ahmad al-omar
ahmad al-omar
|
|
|
|
|
You could do something along these lines:
string s="";
for(int i=0;i<mouseArray.length;i++)
s+=mouseArray.toString();
this.textBox1.Text=s;
I would assume mouseArray would be an array of points.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[^]
|
|
|
|
|
You should use a StringBuilder for that.
|
|
|
|
|
They both accomplish the same thing don't they. Or is their another advantage to using a StringBuilder. I pretty much just use StringBuilder with API commands.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Yes they both accomplish the same thing. However, with the String object, you will create several thousands of temporary String objects since they are immutable. With a StringBuilder object, you only create one object (plus the final String object) and you can manage memory allocation.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
thank you its work but its appears as (System.Int32[]) all the values are the same
ahmad al-omar
|
|
|
|
|
Try this instead:
StringBuilder sb = new StringBuilder();
for(int i=0;i<mouseArray.Length;i++)
{
sb.Append(mouseArray[i].ToString());
sb.Append(Environment.NewLine);
}
this.textBox1.Text=sb.ToString();
|
|
|
|
|
thank you its work but its appears as (System.Int32[]) all the values are the same
ahmad al-omar
|
|
|
|
|
Hi,
I would suggest you consider a ListBox instead of a TextBox;
it avoids having to concatenate all the strings and will result in much better
performance.
|
|
|
|
|
I would suggest you use arraylist achieve as mentioned by others, for more information on arraylist visit....
http://msdn2.microsoft.com/en-us/library/system.collections.arraylist(VS.71).aspx
Regards,
Jaiprakash M Bankolli
jaiprakash.bankolli@gmail.com
http://jaiprakash.blog.com/
|
|
|
|
|
In the code below:
string temp = "http://www.com:8080/";
string pattern = @"^(?<protocol>\w+)://[^/]+?(?<port>:\d+)?/";
Regex r = new Regex(pattern, RegexOptions.Multiline);
MessageBox.Show(r.Match(temp).Result("${prot}${port}"));
I wonder what [^/]+? means and how it matches the temp string, while if I omit ? in [^/]+ it wouldn't give me the correct result. I have read something about lazy plus which is +? but it rather confused me . Does anybody have any idea about this? Or any useful reference about regular expressions? The documentations in MSDN or other places are not sufficient at all.
Thanks in advance
|
|
|
|
|
[^/] is a set that matches any character but /.
+ is the same as {1,}, i.e. repeats one or more times.
? makes the match non-greedy, i.e. it will match as few characters as possible.
If the pattern was greedy, it would match all characters up to the next slash. That means that it would also match all of the digits in the port number except the last one, as that last digit is the minimum needed for the rest of the pattern to match.
---
single minded; short sighted; long gone;
|
|
|
|
|
string temp = "http://www.com:8080/";
string pattern = @"^(?<protocol>\w+)://[^/]+?(?<port>:\d+)?/";
Well as you said, the part [^/]+ could be greedy and consume "www.com:8080" but in the next part we have a colon that forces us to match it with the : in the string. So I think neither of question marks in [^/]+? and (?<port>:\d+)? did their missions! I mean in this case, the pattern had to split the rest of the string to two exact parts. No other permutations could be thought of. The spiltted parts are "www.com" and ":8080/". So in fact, the pattern @"^(?<protocol>\w+)://[^/]+(?<port>:\d+)/" would have a same result for the temp string, right?
|
|
|
|
|
hamidkhan wrote: but in the next part we have a colon that forces us to match it with the : in the string.
No, you don't. The colon is the part of "(?:" which starts a non-matching group.
---
single minded; short sighted; long gone;
|
|
|
|