コード例 #1
0
        /// <summary>
        /// 增加时间点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddBtn_Click(object sender, EventArgs e)
        {
            saveButton.Visible = true;

            Button btn     = (Button)sender;
            Panel  panel   = (Panel)btn.Parent;
            int    minutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;

            if ((int)panel.Tag == addTurnOnTimePointBtnTag)
            {
                if (currentControllerItem.OnTimerCount >= 8)
                {
                    MessageBox.Show("Eight time points at most!");
                    return;
                }

                // 增加一个时间点
                CreateTimePointRow(timePanel, 10000, currentControllerItem.OnTimerCount, rowHeight, HelperTool.ConverMinutes2DateTime(minutes), 0);

                // 往下移动添加按钮
                btn.Parent.Location = new Point(btn.Parent.Location.X, btn.Parent.Location.Y + rowHeight);

                currentControllerItem.OnTimersMinutes.Add(HelperTool.GetDefaultMinutes());

                var defaultColorValues = HelperTool.GetDefaultColorValues(HelperTool.GetChannelNum());

                currentControllerItem.OnTimersColorValues.Add(defaultColorValues);

                // SetTrackBarColorValue(this.trackBars, this.labels, currentControllerItem.OnTimersColorValues[currentControllerItem.OnTimerCount].ToArray());

                currentControllerItem.OnTimerCount++;
            }
            else if ((int)panel.Tag == addTurnOffTimePointBtnTag)
            {
                if (currentControllerItem.OffTimerCount >= 8)
                {
                    MessageBox.Show("Eight time points at most!");
                    return;
                }

                // 增加一个时间点
                CreateTimePointRow(timePanel, 20000, currentControllerItem.OffTimerCount, rowHeight, HelperTool.ConverMinutes2DateTime(minutes), 299);

                currentControllerItem.OffTimersMinutes.Add(HelperTool.GetDefaultMinutes());

                // 往下移动添加按钮
                btn.Parent.Location = new Point(btn.Parent.Location.X, btn.Parent.Location.Y + rowHeight);

                currentControllerItem.OffTimerCount++;
            }

            DrawChart(currentControllerItem);
        }