public DlgWaypointsManager(PictureManager pictureManager, CameraManager cameraManager, int mode, long trackIdToSelect)
        {
            LayerWaypoints.This.makeRouteMode = false;	// just in case route mode is still on

            if(This != null)
            {
                This.Dispose();
                //GC.Collect();
                //GC.WaitForPendingFinalizers();
            }
            This = this;

            m_pictureManager = pictureManager;
            m_cameraManager = cameraManager;
            m_trackIdToSelect = trackIdToSelect;
            m_routeIdToSelect = trackIdToSelect;

            InitializeComponent();

            this.SuspendLayout();
            if(Project.fitsScreen(wptManagerX, wptManagerY, Project.wptManagerWidth, Project.wptManagerHeight))
            {
                inResize = true;
                this.Location = new Point(wptManagerX, wptManagerY);
                this.ClientSize = new System.Drawing.Size(Project.wptManagerWidth, Project.wptManagerHeight);
                inResize = false;
            }

            this.fromTimeDateTimePicker.CustomFormat = "h:mm tt";
            this.toTimeDateTimePicker.CustomFormat = "h:mm tt";
            this.aroundTimeTimeDateTimePicker.CustomFormat = "h:mm tt";

            SetTimeFilterDefaults();

            showWaypointsCheckBox.Checked = Project.drawWaypoints;
            showTrackpointsCheckBox.Checked = Project.drawTrackpoints;
            showNumbersCheckBox.Checked = Project.showTrackpointNumbers;
            showNamesCheckBox.Checked = Project.showWaypointNames;
            sanityCheckBox.Checked = Project.sanityFilter;
            colorElevTracksCheckBox.Checked  = Project.trackElevColor;
            colorSpeedTracksCheckBox.Checked = Project.trackSpeedColor;

            // order of tabs: tracks-trackpoints-routes-waypoints-filter-options
            switch(mode)
            {
                default:
                case 0:
                    // stay on the last chosen
                    rebuildTracksTab();
                    rebuildRoutesTab();
                    rebuildWaypointsTab();
                    // never jump straight to trackpoints tab:
                    tabControl1.SelectedIndex = (selectedTabIndex == 1 || selectedTabIndex == 2) ? 0 : selectedTabIndex;
                    if(tabControl1.SelectedTab == tracksTabPage || tabControl1.SelectedTab == routesTabPage)
                    {
                        prevSelectedTab = tabControl1.SelectedTab;
                    }
                    break;
                case 1:
                    // tracks tab, show the grid:
                    rebuildTracksTab();
                    rebuildRoutesTab();
                    prevSelectedTab = this.tracksTabPage;
                    break;
                case 2:
                    // go to Options tab
                    rebuildTracksTab();
                    rebuildRoutesTab();
                    prevSelectedTab = this.tracksTabPage;
                    tabControl1.SelectedTab = this.optionsTabPage;
                    break;
                case 3:
                    // routes tab, show the grid:
                    rebuildTracksTab();
                    rebuildRoutesTab();
                    tabControl1.SelectedTab = this.routesTabPage;
                    prevSelectedTab = this.routesTabPage;
                    break;
            }

            switch(m_timeFilterMode)
            {
                case 0:		// from/to
                    setFilterModeFromTo();
                    fromToRadioButton.Checked = true;
                    break;
                case 1:		// around time
                    setFilterModeAroundTime();
                    aroundTimeRadioButton.Checked = true;
                    break;
                default:	// no filter
                    setFilterModeNone();
                    noFilterRadioButton.Checked = true;
                    break;
            }

            breakTimeComboBox.SelectedIndex = breakTimeIndex(Project.breakTimeMinutes);
            aroundTimeComboBox.SelectedIndex = aroundTimeIndex(aroundTimeMinutes);
            playSleepTimeMs = 500 + (playSpeedTrackBar.Maximum - playSpeedTrackBar.Value) * 200;
            Project.setDlgIcon(this);

            this.waypointsDataGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.waypointsDataGrid_MouseUp);
            this.trackpointsDataGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.trackpointsDataGrid_MouseUp);
            setColorPaletteButtons();
            colorPaletteMessageLabel.Text = "Note: track/route colors are picked\nrandomly from the choices above, unless explicitly set.";
            try
            {
                trackThicknessNumericUpDown.Value = (decimal)TrackPalette.penTrackThickness;
                routeThicknessNumericUpDown.Value = (decimal)TrackPalette.penRouteThickness;
                this.pointsPerRouteNumericUpDown.Value = (decimal)Project.gpsMaxPointsPerRoute;
            }
            catch {}

            graphByTimeControl = new LibGui.GraphByTimeControl();
            this.graphPanel.Controls.Add(graphByTimeControl);
            this.graphByTimeControl.Dock = System.Windows.Forms.DockStyle.Fill;
            this.graphByTimeControl.Name = "graphByTimeControl";

            inSet = true;

            timeUtcRadioButton.Checked  = Project.useUtcTime;
            timeLocalRadioButton.Checked  = !Project.useUtcTime;
            setUtcLabels();

            inSet = false;

            this.ResumeLayout(true);
        }
        private void DlgEarthquakesManager_Load(object sender, System.EventArgs e)
        {
            inSet = true;	// avoid collecting values on programmatic set
            Cursor.Current = Cursors.WaitCursor;

            this.gridPanel.SuspendLayout();

            eqDataGrid = new MyDataGrid();
            ((System.ComponentModel.ISupportInitialize)(eqDataGrid)).BeginInit();
            this.gridPanel.Controls.Add(eqDataGrid);
            this.eqDataGrid.BackgroundColor = System.Drawing.SystemColors.Window;
            this.eqDataGrid.DataMember = "";
            this.eqDataGrid.Dock = System.Windows.Forms.DockStyle.Fill;
            this.eqDataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.eqDataGrid.Name = "eqDataGrid";
            this.eqDataGrid.Size = new System.Drawing.Size(824, 511);
            this.eqDataGrid.TabIndex = 6;
            this.eqDataGrid.RowHeadersVisible = false;
            this.eqDataGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.eqDataGrid_MouseUp);
            ((System.ComponentModel.ISupportInitialize)(this.eqDataGrid)).EndInit();

            this.gridPanel.ResumeLayout();

            this.graphTabPage.SuspendLayout();

            graphByTimeControl = new LibGui.GraphByTimeControl();
            this.graphPanel.Controls.Add(graphByTimeControl);
            this.graphByTimeControl.Dock = System.Windows.Forms.DockStyle.Fill;
            this.graphByTimeControl.Name = "graphByTimeControl";

            this.graphTabPage.ResumeLayout();

            switch (m_scope)
            {
                case 0:		// world
                    scopeWorldRadioButton.Checked = true;
                    scopeViewRadioButton.Checked = false;
                    break;
                default:
                case 1:		// visible on map
                    m_scope = 1;
                    scopeWorldRadioButton.Checked = false;
                    scopeViewRadioButton.Checked = true;
                    break;
            }

            if(Project.fitsScreen(100, 100, Project.eqManagerWidth, Project.eqManagerHeight))
            {
                this.Size = new Size(Project.eqManagerWidth, Project.eqManagerHeight);
            }

            this.fromTimeDateTimePicker.CustomFormat = "h:mm tt";
            this.toTimeDateTimePicker.CustomFormat = "h:mm tt";
            this.aroundTimeTimeDateTimePicker.CustomFormat = "h:mm tt";

            SetFilterDefaults();
            inSet = true;	// once again, as SetFilterDefaults resets it

            switch(m_mode)
            {
                default:
                case 0:			// stay on the last chosen
                    rebuildTableTab(false);
                    if(selectedTab == 1)
                    {
                        rebuildGraphTab();
                    }
                    tabControl1.SelectedIndex = selectedTab;
                    break;
                case 1:			// Table tab, show the DataGrid:
                    rebuildTableTab(false);
                    break;
                case 2:			// Graph tab
                    // make sure the data is there:
                    rebuildTableTab(false);
                    rebuildGraphTab();
                    // go to Graph tab
                    tabControl1.SelectedIndex = 1;
                    break;
                case 3:			// Filter tab:
                    tabControl1.SelectedIndex = 2;
                    break;
                case 4:			// stay on the last chosen, unless it was a Filter (then switch to Graph)
                    if(selectedTab != 1 && selectedTab != 0)
                    {
                        selectedTab = 1;
                    }
                    rebuildTableTab(false);
                    if(selectedTab == 1)
                    {
                        rebuildGraphTab();
                    }
                    tabControl1.SelectedIndex = selectedTab;
                    break;
            }

            magFilterCheckBox.Checked = TimeMagnitudeFilter.EnabledMagn;	// used in setFilter...() below

            switch(m_timeFilterMode)
            {
                case 0:		// from/to
                    setFilterModeFromTo();
                    fromToRadioButton.Checked = true;
                    break;
                case 1:		// around time
                    setFilterModeAroundTime();
                    aroundTimeRadioButton.Checked = true;
                    break;
                default:	// no filter
                    setFilterModeNone();
                    noFilterRadioButton.Checked = true;
                    break;
            }

            aroundTimeComboBox.SelectedIndex = aroundTimeIndex(aroundTimeMinutes);

            magFromNumericUpDown.Enabled = magFilterCheckBox.Checked;
            magToNumericUpDown.Enabled = magFilterCheckBox.Checked;
            scopeSelectedGraphRadioButton.Enabled = false;				// do not allow clicking on it. Use button to zoom to selected interval

            magFromNumericUpDown.Value = (decimal)TimeMagnitudeFilter.fromMagn;
            magToNumericUpDown.Value = (decimal)TimeMagnitudeFilter.toMagn;

            timeUtcRadioButton.Checked  = Project.useUtcTime;
            timeUtc2RadioButton.Checked = Project.useUtcTime;
            timeUtc3RadioButton.Checked = Project.useUtcTime;
            timeLocalRadioButton.Checked  = !Project.useUtcTime;
            timeLocal2RadioButton.Checked = !Project.useUtcTime;
            timeLocal3RadioButton.Checked = !Project.useUtcTime;
            setUtcLabels();

            inSet = false;

            if(EarthquakesCache.EarthquakesAll.Count < 10)
            {
                string msg =  "There are no earthquakes in the cache.\n\nThis may happen because you opened this form while earthquakes were still loading into the program.\n\nPlease close this form and reopen when earthquakes are fully loaded.";
                Project.ShowPopup(tabControl1, msg, Point.Empty);
            }
            else
            {
                if(m_scope != 0 && m_eqDS.Tables[0].Rows.Count == 0)
                {
                    //Project.MessageBox(this, "There are no earthquakes on the visible map.\n\nTry switching to \"world wide\" to see more, or zoom out.");
                    //Point popupOffset = new Point(5, -5);
                    //Point screenPoint = scopeFilteredRadioButton.PointToScreen(popupOffset);
                    string msg =  "There are no earthquakes on the visible map.\nTry switching to \"world wide\" to see more, or zoom out.";
                    Project.ShowPopup(scopeFilteredRadioButton, msg, Point.Empty);
                }
            }
        }