Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add a the reference to the KVP in the dictionary to the Textbox's <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tag.aspx" rel="nofollow">Tag</a> property. When the user changes the color, get the KVP from the Tag property and change the value in the KVP. I provide insight to the Tag property on my blog C<a href="http://omegacoder.com/?p=66" rel="nofollow"># Winforms and the Hidden Association Tag</a>. WPF/Silverlight also use the Tag property on controls as well.. </p> <p>--- Edit per user request ---</p> <p>I am not sure why you need to enumerate a dictionary. The whole point of a dictionary is to quickly get the key. My example uses that and does not do the for loop.</p> <p>... The initialization location....</p> <pre><code>var myDictionary = new Dictionary&lt;string, Tuple&lt;string, System.Drawing.Color&gt;&gt;() { { "Black", new Tuple&lt;string,System.Drawing.Color&gt;("White", Color.Green) }, { "White", new Tuple&lt;string,System.Drawing.Color&gt;("Black", Color.Red) } }; </code></pre> <p>... (later in code)...</p> <p>private void btnTrans_Click(object sender, EventArgs e)<br> { </p> <pre><code>var key = inputBx.Text; // Let us say "White" if (myDictionary.ContainsKey(key)) { var targetColor = myDictionary[key]; // Just get the value outputBx.Select(0, targetColor.Item1.Length); outputBx.SelectionColor = targetColor.Item2; outputBx.Text = targetColor.Item1; } else { outputBx.Text = "Unknown"; } </code></pre> <p>}</p> <p>Check out my blog article on dictionaries for more info <a href="http://omegacoder.com/?p=188" rel="nofollow">C# Dictionary Tricks</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload