public static void UpdateProgressBar2(ColorProgressBar.ColorProgressBar prg, int value) { try { if (prg.InvokeRequired) { UpdateProgressBarCallback2 d = UpdateProgressBar2; prg.Invoke(d, prg, value); return; } prg.Value = value; } catch { // This catch is simply here to avoid the OCCASIONAL crash of the application when closing it by pressing the stop button in visual studio while it is running tasks } }
private void UpdateBar(UAVCommons.UAVSingleParameter value, ColorProgressBar.ColorProgressBar bar) { bar.Minimum = Convert.ToInt32(value.Min) * 100; bar.Maximum = Convert.ToInt32(value.Max) * 100; bar.Value = Convert.ToInt32(Convert.ToDouble(value.Value) * 100); bar.Refresh(); }
/// <summary> /// Constructor /// </summary> public SetupBoxesForm() { // // Required for Windows Form Designer support // InitializeComponent(); // MLifter.Classes.Help.SetHelpNameSpace(MainHelp); Loading = true; checkBoxAutoBoxSize.Checked = Dictionary.AutoBoxSize; // Create labels and meters } for (int i = 0; i < Dictionary.Boxes.Count; i++) { BoxLabels[i] = new Label(); BoxLabels[i].Parent = GBBoxes; BoxLabels[i].Left = 7; BoxLabels[i].Top = 19 * i + LInfo.Top + LInfo.Height + 5; BoxLabels[i].Height = 14; BoxLabels[i].Width = 95; BoxLabels[i].AutoSize = true; BoxSize[i] = new Label(); BoxSize[i].Parent = GBBoxes; BoxSize[i].TextAlign = ContentAlignment.MiddleRight; BoxSize[i].Anchor = AnchorStyles.Right; BoxSize[i].Left = GBBoxes.Width - 120; BoxSize[i].Top = BoxLabels[i].Top; BoxSize[i].Width = 50; BoxSize[i].Height = 14; if (i > 0 && i < Dictionary.Boxes.Count - 1) { BoxMaxSize[i - 1] = new NumericUpDown(); BoxMaxSize[i - 1].Parent = GBBoxes; BoxMaxSize[i - 1].Maximum = 64000; BoxMaxSize[i - 1].Minimum = 2; BoxMaxSize[i - 1].Size = new System.Drawing.Size(58, 14); BoxMaxSize[i - 1].Value = BoxMaxSize[i - 1].Minimum; BoxMaxSize[i - 1].ValueChanged += new EventHandler(SEMax_ValueChanged); BoxMaxSize[i - 1].LostFocus += new EventHandler(SEMax_TextChanged); BoxMaxSize[i - 1].Tag = i; BoxMaxSize[i - 1].Top = BoxLabels[i].Top - 3; BoxMaxSize[i - 1].Left = GBBoxes.Width - 65; } BoxIndicator[i] = new ColorProgressBar(); BoxIndicator[i].Parent = GBBoxes; BoxIndicator[i].Left = BoxLabels[i].Left + BoxLabels[i].Width + 5; BoxIndicator[i].Top = BoxLabels[i].Top; BoxIndicator[i].Step = 1; BoxIndicator[i].Width = GBBoxes.Width - BoxIndicator[i].Left - 120; BoxIndicator[i].Height = 14; BoxIndicator[i].BarColor = Color.SteelBlue; BoxIndicator[i].FillStyle = ColorProgressBar.FillStyles.Solid; } BoxLabelSizePool.Parent = GBBoxes; BoxLabelSizePool.Top = BoxLabels[0].Top; BoxLabelSizePool.Left = GBBoxes.Width - 65; BoxLabelSizePool.TextAlign = ContentAlignment.MiddleLeft; BoxLabelSizePool.Size = new System.Drawing.Size(58, 14); BoxLabelSizePark.Parent = GBBoxes; BoxLabelSizePark.Top = BoxLabels[10].Top; BoxLabelSizePark.Left = GBBoxes.Width - 65; BoxLabelSizePark.TextAlign = ContentAlignment.MiddleLeft; BoxLabelSizePark.Size = new System.Drawing.Size(58, 14); int lastBox = Dictionary.Boxes.Count - 1; for (int i = lastBox - 1; i >= 0; i--) { BoxIndicator[i].DataBindings.Add(new Binding("Left", BoxIndicator[lastBox], "Left")); BoxIndicator[i].DataBindings.Add(new Binding("Width", BoxIndicator[lastBox], "Width")); } BoxLabels[0].Text = Resources.SETUPBOXES_BOXLABEL0_TEXT; for (int i = 1; i < Dictionary.Boxes.Count; i++) { BoxLabels[i].Text = Resources.SETUPBOXES_BOXLABELI_TEXT + " " + i.ToString(); } BoxIndicator[lastBox].Left = BoxLabels[lastBox].Left + BoxLabels[lastBox].Width + 5; BoxIndicator[lastBox].Width = GBBoxes.Width - BoxIndicator[lastBox].Left - 120; Loading = false; UpdateMeters(); }
public MainWindow() { InitializeComponent(); var str = toolTip.GetToolTip(popSeedTextBox); toolTip.SetToolTip(popSeedLabel, str); str = toolTip.GetToolTip(trackSeedTextBox); toolTip.SetToolTip(trackSeedLabel, str); str = toolTip.GetToolTip(mutationRateTextBox); toolTip.SetToolTip(mutationRateLabel, str); str = toolTip.GetToolTip(clonesComboBox); toolTip.SetToolTip(clonesLabel, str); str = toolTip.GetToolTip(randomCarsComboBox); toolTip.SetToolTip(randomCarsLabel, str); // initialize default values mutationRateTextBox.Text = Settings.Default.MutationRate.ToString( CultureInfo.CurrentCulture); FollowingCarId = LeaderCarId; // at most half of the population can be clones, and half can be random clonesComboBox.Items.Clear(); randomCarsComboBox.Items.Clear(); for (var i = 0; i <= PopulationSize; i++) { clonesComboBox.Items.Add(i); randomCarsComboBox.Items.Add(i); } clonesComboBox.SelectedIndex = Properties.Settings.Default.NumClones; randomCarsComboBox.SelectedIndex = Properties.Settings.Default.NumRandom; for (var i = 0; i < PopulationSize; i++) { var pb = new ColorProgressBar { Id = i, Minimum = 0, Maximum = 100, Value = 100, Text = i.ToString(), Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Bold), Margin = new Padding(0) }; pb.MouseClick += (sender, args) => { if (args.Button == MouseButtons.Left) { FollowingCarId = ((ColorProgressBar)sender).Id; } }; toolTip.SetToolTip(pb, string.Format("Click to view car {0}", i)); // set a context menu to manually kill cars var contextMenu = new ContextMenu(); contextMenu.Popup += (sender, args) => OnPauseSimulation(); contextMenu.Collapse += (sender, args) => OnResumeSimulation(); var menuItem = new MenuItem("Kill"); menuItem.Click += (sender, args) => OnKillCar(pb.Id); contextMenu.MenuItems.Add(menuItem); pb.ContextMenu = contextMenu; populationList.Controls.Add(pb); } }