|
| 1 | +using System; |
| 2 | +using System.Windows.Forms; |
| 3 | + |
| 4 | +namespace OpenEphys.Onix1.Design |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Partial class that holds the stimulus definition UI elements for a <see cref="Headstage64OpticalStimulatorSequenceDialog"/>. |
| 8 | + /// </summary> |
| 9 | + public partial class Headstage64OpticalStimulatorOptions : Form |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Initialize a new <see cref="Headstage64OpticalStimulatorOptions"/> dialog. |
| 13 | + /// </summary> |
| 14 | + public Headstage64OpticalStimulatorOptions() |
| 15 | + { |
| 16 | + InitializeComponent(); |
| 17 | + } |
| 18 | + |
| 19 | + private void SynchronizeTextBoxAndTrackBar(TextBox textBox, TrackBar trackBar, double value) |
| 20 | + { |
| 21 | + if (textBox == null || trackBar == null) |
| 22 | + { |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + textBox.Text = value.ToString(); |
| 27 | + trackBar.Value = (int)value; |
| 28 | + } |
| 29 | + |
| 30 | + private double VerifyPercentLimits(double value) |
| 31 | + { |
| 32 | + double MinimumPercent = 0; |
| 33 | + double MaximumPercent = 100; |
| 34 | + |
| 35 | + if (value < MinimumPercent) |
| 36 | + { |
| 37 | + return MinimumPercent; |
| 38 | + } |
| 39 | + else if (value > MaximumPercent) |
| 40 | + { |
| 41 | + return MaximumPercent; |
| 42 | + } |
| 43 | + else |
| 44 | + { |
| 45 | + return value; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + private void KeyPressed(object sender, KeyPressEventArgs e) |
| 50 | + { |
| 51 | + if (e.KeyChar == '\r') |
| 52 | + { |
| 53 | + ChannelPercentTextChanged(sender, null); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + private void ChannelPercentTextChanged(object sender, EventArgs eventArgs) |
| 58 | + { |
| 59 | + if (sender is TextBox tb) |
| 60 | + { |
| 61 | + if (tb.Name == textBoxChannelOnePercent.Name) |
| 62 | + { |
| 63 | + if (double.TryParse(tb.Text, out double result)) |
| 64 | + { |
| 65 | + result = VerifyPercentLimits(result); |
| 66 | + SynchronizeTextBoxAndTrackBar(textBoxChannelOnePercent, trackBarChannelOnePercent, result); |
| 67 | + } |
| 68 | + else |
| 69 | + { |
| 70 | + SynchronizeTextBoxAndTrackBar(textBoxChannelOnePercent, trackBarChannelOnePercent, 0); |
| 71 | + } |
| 72 | + } |
| 73 | + else if (tb.Name == textBoxChannelTwoPercent.Name) |
| 74 | + { |
| 75 | + if (double.TryParse(tb.Text, out double result)) |
| 76 | + { |
| 77 | + result = VerifyPercentLimits(result); |
| 78 | + SynchronizeTextBoxAndTrackBar(textBoxChannelTwoPercent, trackBarChannelTwoPercent, result); |
| 79 | + } |
| 80 | + else |
| 81 | + { |
| 82 | + SynchronizeTextBoxAndTrackBar(textBoxChannelTwoPercent, trackBarChannelTwoPercent, 0); |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private void ChannelPercentTrackBarChanged(object sender, EventArgs eventArgs) |
| 89 | + { |
| 90 | + if (sender is TrackBar tb) |
| 91 | + { |
| 92 | + if (tb.Name == trackBarChannelOnePercent.Name) |
| 93 | + { |
| 94 | + SynchronizeTextBoxAndTrackBar(textBoxChannelOnePercent, trackBarChannelOnePercent, trackBarChannelOnePercent.Value); |
| 95 | + } |
| 96 | + else if (tb.Name == trackBarChannelTwoPercent.Name) |
| 97 | + { |
| 98 | + SynchronizeTextBoxAndTrackBar(textBoxChannelTwoPercent, trackBarChannelTwoPercent, trackBarChannelTwoPercent.Value); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments