|
Again, can a Windows Forms app not launch the console application? It can, and you can even run it (the console app) in the background without a shell window.
|
|
|
|
|
|
|
Hello Friends I have a main form in which there is a file menu strip. What I want to do is that when ever I click a menu strip of that menu a new for will be shown and all the menu strip will be disabled. And After I close the new form all the menu strips of the main form will be available again. What Can I write in form Closed method of the 2nd form? Can any one help me?
|
|
|
|
|
You can do like this..
ON MDI Form
public bool MenuItemControl
{
set
{
this.newToolStripMenuItem.Enabled = value;
}
}
ON FORM CLOSED EVENT
MDIParentForm MdiPF = (MDIParentForm)this.MdiParent;
|
|
|
|
|
|
Is there any key/value pair type class which can return "Key" object from "Value" ? I have done this by inheriting from generic Dictionary class. It works pretty well now. But I need to know if there is any predefined classes available. Any ideas ?
|
|
|
|
|
So you want to get values based on keys AND keys based on values?
|
|
|
|
|
Yes. And my collection will have only unique values.
|
|
|
|
|
This is what I have done.
public bool TryGetCategory(string value, out string category)
{
category = null;
if (this.ContainsValue(value))
{
foreach (KeyValuePair<string, string> pair in this)
{
if (pair.Value == value)
{
category = pair.Key;
return true;
}
}
}
return false;
}
This method is in a class which inherits from Dictionary<string,string>
|
|
|
|
|
DictionaryEntry class can be used to get key from value.
|
|
|
|
|
d@nish wrote: DictionaryEntry class
It's a structure, not a class. It's same like key/value pair and it is not a collection.
|
|
|
|
|
N a v a n e e t h wrote: It's a structure, not a class
Oh yes.Sorry.
|
|
|
|
|
There is method GetKeyForItem in KeyedCollectionClass. Is that what you are looking for?
|
|
|
|
|
d@nish wrote: There is method GetKeyForItem in KeyedCollectionClass
Thnaks. But it's an abstract class and I should override the GetKeyForItem method.
|
|
|
|
|
To make that efficiently (without looping through the items in the collection), you need to keep another dictionary where you switch the key and value.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Great. Do you mean putting another dictionary instance which is not visible to outside of class. When new items are added/removed from the main dictionary, this internal one also should synchronize. Right ?
|
|
|
|
|
Yes, that will be the best.
|
|
|
|
|
Thanks. How about the performance if collection is big ?
|
|
|
|
|
N a v a n e e t h wrote: Do you mean putting another dictionary instance which is not visible to outside of class.
Basically, yes. If you want to access items both on key and value, I suggest that you make a class that encapsulates two dictionaries, and only expose methods for adding, removing and do key and value lookups.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Okay. Thanks for that. Will it be an performance overhead if collection is big ?
|
|
|
|
|
N a v a n e e t h wrote: Will it be an performance overhead if collection is big ?
There will be some memory overhead, as a dictionary uses about 20 bytes to keep track of each entry.
Accessing items by key is a O(1) operation, so the size of the dictionary doesn't affect the time to fetch an item (assuming of course that the type of the key doesn't have a lousy algorithm for producing hash values).
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks again guffa. I will go with the solution you suggested.
Guffa wrote: as a dictionary uses about 20 bytes
I am wondering how you are getting the memory details ?
|
|
|
|
|
A dictionary contains two arrays, a bucket index array and an entry array. The bucket index array is an int array and the entry array is an array of the type Entry:
[StructLayout(LayoutKind.Sequential)]
private struct Entry {
public int hashCode;
public int next;
public TKey key;
public TValue value;
}
If the key and the value are reference types, on a 32-bit system the Entry structure will be 4+4+4+4 = 16 bytes. The two arrays always has the same number of items, so for each entry there is one item in the bucket index array (int) and one item in the entry array, which will add up to 20 bytes in this case.
The size of the Entry structure varies depending on the system and data types. For example:
On a 64-bit system, if the key and value are reference types, the Entry structure will be 4+4+8+8 = 24 bytes.
If the key is an Int64 and the value is a Decimal, the Entry structure will be 4+4+8+16 = 32 bytes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|