Exemple #1
0
        private void updataButton_Click(object sender, EventArgs e)
        {
            int[,] daysInPanel = GetDaysInPanel();
            if (daysInPanel[clickInRow, clickInColoum] != 0)
            {
                currentTextEditingDate = new DateTime(
                    currentSelectedDate.Year, currentSelectedDate.Month, daysInPanel[clickInRow, clickInColoum]);

                // 更新数据
                if (NotepadHashtable.Exists(currentTextEditingDate) && noteTextBox.Text.TrimEnd() != "")
                {
                    NotepadHashtable.UpdateText(currentTextEditingDate, noteTextBox.Text);
                    MessageBox.Show("更新成功");
                }
                else
                {
                    MessageBox.Show("更新失败");
                }
            }
        }
Exemple #2
0
        private void calendarContentPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            // 判断鼠标点击了哪一天
            clickInRow    = (int)(e.Location.Y / ((float)calendarContentPanel.Height / 6));
            clickInColoum = (int)(e.Location.X / ((float)calendarContentPanel.Width / 7));

            int[,] daysInPanel = GetDaysInPanel();

            // 点击的单元格有元素存在
            if (daysInPanel[clickInRow, clickInColoum] != 0)
            {
                // 重置当前选中的日期
                currentSelectedDate = new DateTime(currentSelectedDate.Year, currentSelectedDate.Month, daysInPanel[clickInRow, clickInColoum]);
                OnCurrentSelectedDateChanged();
            }

            // 判断鼠标是否点击了日期框右上角的加号(三角形)
            PointF[] topRightTrianglePoints =
            {
                new Point(40, 0),
                new Point(62, 0),
                new Point(62, 20)
            };

            for (int i = 0; i < 3; i++)
            {
                topRightTrianglePoints[i].X += (float)calendarContentPanel.ClientRectangle.Width / 7 * drawPlusInColoum;
                topRightTrianglePoints[i].Y += (float)calendarContentPanel.ClientRectangle.Height / 6 * drawPlusInRow;
            }
            GraphicsPath topRightTrianglePath = new GraphicsPath();

            topRightTrianglePath.AddPolygon(topRightTrianglePoints);
            Region topRightTriangleRegion = new Region(topRightTrianglePath);

            // 取得当前在编辑的文本所对应日历中的日期格子
            currentTextEditingDate = new DateTime(
                currentSelectedDate.Year, currentSelectedDate.Month, daysInPanel[drawPlusInRow, drawPlusInColoum]);


            // 点击了加号,并且文本没有数据
            if (topRightTriangleRegion.IsVisible(e.Location) && noteTextBox.Text.TrimEnd() == "")
            {
                updataButton.Visible = true;
                deleteButton.Visible = true;
                noteTextBox.Visible  = true;
                noteLabel.Visible    = false;
                // 文本框取得焦点
                noteTextBox.Focus();
            }
            // 点击了加号,文本有数据,表示添加文本
            else if (topRightTriangleRegion.IsVisible(e.Location) && noteTextBox.Text.TrimEnd() != "")
            {
                if (!NotepadHashtable.Exists(currentTextEditingDate))
                {
                    NotepadHashtable.AddText(currentTextEditingDate, noteTextBox.Text);
                    MessageBox.Show("添加成功");
                }
                else
                {
                    NotepadHashtable.UpdateText(currentTextEditingDate, noteTextBox.Text);
                    MessageBox.Show("已添加");
                }
            }
            // 检查NotepadHashtable类中当前日期是否有数据,如有则显示
            else if (NotepadHashtable.Exists(currentTextEditingDate))
            {
                noteTextBox.Text = NotepadHashtable.GetText(currentTextEditingDate);

                updataButton.Visible = true;
                deleteButton.Visible = true;
                noteTextBox.Visible  = true;
                noteLabel.Visible    = false;

                // 文本框取得焦点
                noteTextBox.Focus();
            }
            else
            {
                updataButton.Visible = false;
                deleteButton.Visible = false;
                noteTextBox.Visible  = false;
                noteLabel.Visible    = true;
                noteTextBox.Text     = "";

                this.Focus();
            }

            // 重绘
            noteTextBox.Invalidate();
        }