using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Xml; using System.Windows.Forms; using TradeIdeas.XML; using System.Globalization; using System.Threading; namespace TradeIdeas.TIProGUI.CBT { [ToolboxItem(false)] public partial class Example : UserControl, IChild { string IChild.Name { get { return "Example"; } } Control IChild.Body { get { return this; } } bool IChild.CanShowExample { get { return false; } } void IChild.OnShow() { // We could search and try to find a radio button that matches // the current min and max. I don't know how interesthing that is. // In practice, OnShow() is aimed at the tab sheet we got to after // leaving the Example tab sheet. } private readonly IContainer _container; public Example(IContainer container, List examples) { _container = container; InitializeComponent(); RadioButton previous = allStocksRadioButton; foreach (XmlNode example in examples) { RadioButton current = new RadioButton(); current.Parent = this; current.Visible = true; current.Left = allStocksRadioButton.Left; current.Top = previous.Top + previous.Height + allStocksRadioButton.Top; current.Text = example.PropertyForCulture("DESCRIPTION", "***"); current.Tag = example; current.AutoSize = true; current.CheckedChanged += RadioButton_CheckedChanged; previous = current; } _container.MaxTextBox.TextChanged += new EventHandler(TextBox_TextChanged); _container.MinTextBox.TextChanged += new EventHandler(TextBox_TextChanged); } static public Dictionary GetAll() { Dictionary result = new Dictionary(); foreach (XmlNode exampleSet in ConfigDemoUserControl.ConfigDemoXml.Node("EXAMPLE_SETS").Enum()) { List codes = new List(); List examples = new List(); foreach (XmlNode node in exampleSet) { switch (node.SafeName()) { case "FILTER": codes.Add(node.Property("CODE")); break; case "EXAMPLE": examples.Add(node); break; } } foreach (string code in codes) result[code] = delegate(IContainer container) { return new Example(container, examples); }; } return result; } private const String PLACEHOLDER = "⁂"; /// /// The examples are stored in English, i.e. "1.00" for 1, "1.50" for 1 and a half. /// Change these to match the user's language. We immediately interpret them in the /// user's language so this is required. /// /// /// private String FixLanguage(String asEnglish) { NumberFormatInfo numberFormat = NumberFormatInfo.CurrentInfo; return asEnglish.Replace(",", PLACEHOLDER).Replace(".", numberFormat.NumberDecimalSeparator).Replace(PLACEHOLDER, numberFormat.NumberGroupSeparator); } private void RadioButton_CheckedChanged(object sender, EventArgs e) { if (_ignoreChanges) return; RadioButton rb = (RadioButton)sender; if (!rb.Checked) return; XmlNode example = rb.Tag as XmlNode; _ignoreChanges = true; _container.MinTextBox.Text = FixLanguage(example.Property("MIN")); _container.MaxTextBox.Text = FixLanguage(example.Property("MAX")); _ignoreChanges = false; _container.ShowExample(); } private bool _ignoreChanges; void TextBox_TextChanged(object sender, EventArgs e) { if (_ignoreChanges) return; _ignoreChanges = true; allStocksRadioButton.Checked = true; allStocksRadioButton.Checked = false; _ignoreChanges = false; } } }