private void SmootherList_MouseUp(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { int clickedIndex = IndexFromPoint(e.Location); if (clickedIndex >= 0) { Smoother smoother = Items[clickedIndex] as Smoother; if (smoother == null) { throw new NullReferenceException("Expected Smoother objects in Items"); } string updateWindowTitle = "Updating " + smoother.GetType().Name + "..."; if (smoother is KdeSmoother) { KdeSmoother kdeSmoother = smoother as KdeSmoother; DynamicForm f = new DynamicForm("Set KDE smoother parameters", DynamicForm.CloseButtons.OkCancel); f.AddNumericUpdown("Sample size:", kdeSmoother.SampleSize, 0, 1, decimal.MaxValue, 1, "sample_size"); f.AddCheckBox("Normalize:", ContentAlignment.MiddleRight, kdeSmoother.Normalize, "normalize"); if (f.ShowDialog() == DialogResult.OK) { try { kdeSmoother.SampleSize = Convert.ToInt32(f.GetValue <decimal>("sample_size")); } catch (Exception ex) { MessageBox.Show("Invalid value for sample size: " + ex.Message); } kdeSmoother.Normalize = f.GetValue <bool>("normalize"); } } else if (smoother is WeightedAverageSmoother) { WeightedAverageSmoother avgSmoother = smoother as WeightedAverageSmoother; DynamicForm f = new DynamicForm("Set weighted average smoother parameters", DynamicForm.CloseButtons.OkCancel); f.AddNumericUpdown("Minimum:", (decimal)avgSmoother.Minimum, 0, 0, decimal.MaxValue, 1, "minimum"); f.AddNumericUpdown("Maximum:", (decimal)avgSmoother.Maximum, 0, 0, decimal.MaxValue, 1, "maximum"); if (f.ShowDialog() == DialogResult.OK) { try { avgSmoother.Minimum = Convert.ToDouble(f.GetValue <decimal>("minimum")); } catch (Exception ex) { MessageBox.Show("Invalid value for minimum: " + ex.Message); } try { double value = Convert.ToDouble(f.GetValue <decimal>("maximum")); if (value < avgSmoother.Minimum) { avgSmoother.Maximum = avgSmoother.Minimum + 500; throw new Exception("Maximum must be greater than or equal to minimum (" + avgSmoother.Minimum + "). Setting maximum to " + avgSmoother.Maximum + "."); } avgSmoother.Maximum = value; } catch (Exception ex) { MessageBox.Show("Invalid value for maximum: " + ex.Message); } } } else if (smoother is MarsSmoother) { MarsSmoother marsSmoother = smoother as MarsSmoother; DynamicForm f = new DynamicForm("Set MARS smoother parameters", DynamicForm.CloseButtons.OkCancel); f.AddNumericUpdown("Number of considered parent terms (-1 for all):", marsSmoother.ConsideredParentTerms, 0, -1, decimal.MaxValue, 1, "parent"); f.AddNumericUpdown("Degree of interaction:", marsSmoother.InteractionDegree, 0, 1, decimal.MaxValue, 1, "interaction"); f.AddNumericUpdown("Number of knots (-1 for auto):", marsSmoother.NumberOfKnots, 0, -1, decimal.MaxValue, 1, "knots"); if (f.ShowDialog() == DialogResult.OK) { try { marsSmoother.ConsideredParentTerms = Convert.ToInt32(f.GetValue <decimal>("parent")); } catch (Exception ex) { MessageBox.Show("Invalid value for parent terms: " + ex.Message); } try { marsSmoother.InteractionDegree = Convert.ToInt32(f.GetValue <decimal>("interaction")); } catch (Exception ex) { MessageBox.Show("Invalid value for interaction degree: " + ex.Message); } try { marsSmoother.NumberOfKnots = Convert.ToInt32(f.GetValue <decimal>("knots")); } catch (Exception ex) { MessageBox.Show("Invalid value for number of knots: " + ex.Message); } } } else { throw new NotImplementedException("Unrecognized smoother type: " + smoother.GetType().FullName); } } } }