⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cal.cs

📁 windows modile 编程.实现简单的crm功能
💻 CS
字号:
using System;
//using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Opportune.CalEx
{
	public partial class Cal : UserControl, IOppoCal, IMyCalChanged
	{
		public event CalendarChangedHandler CalendarChangedEvt;
		public event SelectedDateChangedHandler SelectedDateChangedEvt;
		public event ImageClickedHandler ImageClickedEvt;
		MyCalendar _calendar;

		public Cal()
		{
			_now = DateTime.Now;
			InitializeComponent();
			labelToday.Text = "Today:" + _now.ToString("dd/MM/yyyy");

			_calendar = new MyCalendar(this.panel3, _now);
			this.labelCurrYear.Text = _calendar.Year.ToString();
			this.labelCurrMonth.Text = _calendar.Month.ToString();
		}

		private void Cal_ParentChanged(object sender, EventArgs e)
		{
			if (Parent == null)
				return;
			this.Left = 0;
			this.Top = 0;
			this.Width = this.Parent.ClientSize.Width;
			this.Height = this.Parent.ClientSize.Height;

			this.panel1.Location = new Point(1, 1);
			this.panel1.Size = new Size(this.Width - 2, 27);
			this.buttonPrevMonth.Location = new Point(2, 2);
			this.buttonPrevMonth.Size = new Size(27, 18);
			this.buttonNextMonth.Location = new Point(this.Width - 28, 2);
			this.buttonNextMonth.Size = new Size(27, 18);
			this.labelCurrYear.Location = new Point(this.Width / 2 + 1, 2);
			this.labelCurrYear.Size = new Size(this.Width / 2 - 36, 16);
			this.textYear.Location = new Point(this.Width / 2 + 1, 2);
			this.textYear.Size = new Size(this.Width / 2 - 36, 16);
			this.textYear.Visible = false;
			this.labelCurrMonth.Location = new Point(36, 2);
			this.labelCurrMonth.Size = new Size(this.Width / 2 - 36, 16);
			this.panel2.Location = new Point(1, 28);
			this.panel2.Size = new Size(this.Width - 2, 16);
			this.panel4.Location = new Point(1, this.Height - 28);
			this.panel4.Size = new Size(this.Width - 2, 27);
			this.panel3.Location = new Point(1, 45);
			this.panel3.Size = new Size(this.Width - 2, this.Height - 76);
			labelToday.Location = new Point(1, 2);
			labelToday.Size = new Size(this.Width / 2 + 16, 16);
			buttonGotoToday.Location = new Point(this.Width / 2 + 20, 2);
			buttonGotoToday.Size = new Size(this.Width / 2 - 24, 16);
		}

		private void panel2_Paint(object sender, PaintEventArgs e)
		{
			IntPtr hdc = e.Graphics.GetHdc();
			Graphics newGraphics = Graphics.FromHdc(hdc);

			int width = panel2.Width / 7;
			int height = panel2.Height;
			Font f = new Font("Arial", 10, FontStyle.Bold);
			SolidBrush br = new SolidBrush(Color.Blue);
			string week = "SunMonTueWedThuFriSat";
			for (int i = 0; i < 7; i++)
			{
				newGraphics.DrawString(week.Substring(i * 3, 3), f, br,
					new RectangleF(width * i, 0, width * (i + 1), height));
			}
			e.Graphics.ReleaseHdc(hdc);
		}

		public void AddImage(DateTime date, Image image)
		{
			_calendar.SetImage(date, image,true);
		}
		public void AddImages(DateTime[] date, Image image)
		{
			for(int i=0;i<date.Length ;i++)
				_calendar.SetImage(date[i], image,false);
			panel3.Invalidate();
		}
		public void RemoveImage(DateTime date)
		{
			_calendar.SetImage(date, null,true);
		}
		public void RemoveImages(DateTime[] date)
		{
			for (int i = 0; i < date.Length; i++)
				_calendar.SetImage(date[i], null,false);
			panel3.Invalidate();
		}
		public void ClearImage()
		{
			_calendar.ClearImage();
			panel3.Invalidate();

		}
		public void DoCalChanged(int newYear, int newMonth)
		{
			this.panel3.Invalidate();
			this.labelCurrYear.Text = _calendar.Year.ToString();
			this.labelCurrMonth.Text = _calendar.Month.ToString();

			if (this.CalendarChangedEvt != null)
			{
				CalendarChanged e = new CalendarChanged();
				e.Year = newYear;
				e.Month = newMonth;
				this.CalendarChangedEvt(this, e);
			}
		}

		private void panel3_Paint(object sender, PaintEventArgs e)
		{
			IntPtr hdc = e.Graphics.GetHdc();
			Graphics newGraphics = Graphics.FromHdc(hdc);
			int index = _calendar.GetIndexByRect(e.ClipRectangle);
			if (index < 0)
				_calendar.Paint(newGraphics);
			else
				_calendar.RedrawOneCell(newGraphics, index);
			e.Graphics.ReleaseHdc(hdc);
		}

		private void panel3_MouseDown(object sender, MouseEventArgs e)
		{
			_calendar.OnClick(e.X, e.Y);
			this.EnableEditYear(false);
		}

		private void buttonGotoToday_Click(object sender, EventArgs e)
		{
			this.EnableEditYear(false);
			_calendar.MakeTodayVisible();
		}

		private void buttonNextMonth_Click(object sender, EventArgs e)
		{
			_calendar.AdvanceMonth(true);
			this.EnableEditYear(false);
		}

		private void buttonPrevMonth_Click(object sender, EventArgs e)
		{
			_calendar.AdvanceMonth(false);
			this.EnableEditYear(false);
		}
		public void DoSelChanged(DateTime newDate, int newSelIndex)
		{
			if (this.SelectedDateChangedEvt != null)
			{
				SelectedDateChanged e = new SelectedDateChanged();
				e.SelectedDate = newDate;
				this.SelectedDateChangedEvt(this, e);
			}
		}
		public void EnableEditYear(bool bEnabled)
		{
			if (bEnabled)
			{
				if (textYear.Visible == true)
					return;
				this.textYear.Text = this.labelCurrYear.Text;
				textYear.Visible = true;
				textYear.Focus();
				labelCurrYear.Visible = false;
			}
			else
			{
				if (textYear.Visible == false)
					return;
				textYear.Visible = false;
				labelCurrYear.Visible = true;

				int year;
				try
				{
					year = int.Parse(textYear.Text);
				}
				catch (Exception exc)
				{
					return;
				}
				if (year > 1900 && year < 8888)
				{
					_calendar.Year = year;
					panel3.Invalidate();
				}
			}
		}

		private void panel1_MouseDown(object sender, MouseEventArgs e)
		{
			if (this.textYear.Visible == false)
			{
				Rectangle r = new Rectangle(labelCurrYear.Location.X,
					labelCurrYear.Location.Y, labelCurrYear.Size.Width,
					labelCurrYear.Size.Height);
				if (r.Contains(e.X, e.Y))
				{
					EnableEditYear(true);
				}
			}
		}
		public DateTime GetSelectedDate()
		{
			return _calendar.GetSelectedDate();
		}
		public void DoImageClicked(DateTime date, Image image)
		{
			if (this.ImageClickedEvt != null)
			{
				ImageClicked e = new ImageClicked();
				e.ClickedDate = date;
				e.ClickedImage = image;
				this.ImageClickedEvt(this, e);
			}
		}


		public void HandleKeyDown(Keys key)
		{
			_calendar.OnKeyDown(key);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -