返回首页

{A}简介
这种控制套件是一个Windows窗体日历控件的原型设置。NET应用程序。他们创造的概念,Outlook风格的日历可以整合成一个大型的Windows窗体应用程序没有使用第三方库的开销证明。
包括三个控件 - DayScheduleControl,WeekScheduleControl和MonthScheduleControl。控件呈现不同的布局的一系列任命。我不可能有时间,以提高itnbsp;在不久的将来,所以我会释放出他们的希望,他们将对别人有用。
DayScheduleControl是最接近的外观到Outlook。它支持为期一天和五天的看法。

WeekScheduleControl显示一个一周7天。不像DayScheduleControl,它不显示小时插槽。

MonthScheduleControl显示的约会整整一个月。使用代码
Form1类中所包括的测试项目包含控件的使用示例。首先,它的代码创建一个随机任命名单,并设置控件显示当前日期。 CreateRandomAppointments方法加载了随机虚拟数据值得一两个月。

DateTime weekstart = DateTime.Now;

AppointmentList appts = CreateRandomAppointments(weekstart);

weekView1.Date = weekstart;

weekView1.Appointments = appts;

monthView1.Date = weekstart;

monthView1.Appointments = appts;

dayView1.Date = weekstart;

dayView1.Appointments = appts;

dayView2.Date = weekstart;

dayView2.Appointments = appts;

不是CreateRandomAppointments,在一个正常的应用程序,你将建立一个AppointmentList和新增约会对象,像下面这样,使用自己的数据源。{C}
二,创建,移动和编辑事件有线演示方法。
weekView1.AppointmentCreate += calendar_AppointmentAdd;

monthView1.AppointmentCreate += calendar_AppointmentAdd;

dayView1.AppointmentCreate += calendar_AppointmentAdd;

dayView2.AppointmentCreate += calendar_AppointmentAdd;



weekView1.AppointmentMove += calendar_AppointmentMove;

monthView1.AppointmentMove += calendar_AppointmentMove;

dayView1.AppointmentMove += calendar_AppointmentMove;

dayView2.AppointmentMove += calendar_AppointmentMove;



weekView1.AppointmentEdit += calendar_AppointmentEdit;

monthView1.AppointmentEdit += calendar_AppointmentEdit;

dayView1.AppointmentEdit += calendar_AppointmentEdit;

dayView2.AppointmentEdit += calendar_AppointmentEdit;

当用户交互日历约会,事件被激发,所以我们弹出一个自定义对话框处理。在这种情况下NewAppointment是一个对话框,进入约会的标题,开始和结束日期。 MoveAppointment和EditAppointment对话框是相当类似的,他们做了什么。
private void calendar_AppointmentAdd(object sender, AppointmentCreateEventArgs e)

{

    //show a dialog to add an appointment

    using (NewAppointment dialog = new NewAppointment())

    {

        if (e.Date != null)

        {

            dialog.AppointmentDateStart = e.Date.Value;

            dialog.AppointmentDateEnd = e.Date.Value.AddMinutes(15);

        }

        DialogResult result = dialog.ShowDialog();

        if (result == DialogResult.OK)

        {

            //if the user clicked 'save', save the new appointment 

            string title = dialog.AppointmentTitle;

            DateTime dateStart = dialog.AppointmentDateStart;

            DateTime dateEnd = dialog.AppointmentDateEnd;

            e.Control.Appointments.Add(new ExtendedAppointment() { 

            Subject = title, DateStart = dateStart, DateEnd = dateEnd });



            //have to tell the controls to refresh appointment display

            weekView1.RefreshAppointments();

            monthView1.RefreshAppointments();

            dayView1.RefreshAppointments();

            dayView2.RefreshAppointments();



            //get the controls to repaint 

            weekView1.Invalidate();

            monthView1.Invalidate();

            dayView1.Invalidate();

            dayView2.Invalidate();

        }

    }

}

ExtendedAppointment类是用于增加额外的属性任命。因为这是在测试应用程序位于/移动/编辑创建,你可以添加更多的领域,而无需进入SheduleControls大会的胆量对话框对话框。它如何工作
这些控制的要求:支持Windows 7风格支持键盘访问残疾人士也可以访问不要使用多少内存
三个控件的代码类似,它们都从BaseScheduleControl继承。这个基地的控制手柄拖放隐藏DataGridView的约会,和鼠标点击事件。大部分的代码是连接中隐藏的DataGridView键盘操作的用户界面显示(例如,选定预约),和鼠标操作,反之亦然。
namespace Syd.ScheduleControls

{

    /// <summary>

    /// The BaseScheduleControl defines properties common to 

    /// the three schedule controls. 

    /// </summary>

    public  partial class BaseScheduleControl : Control, 

    System.ComponentModel.ISupportInitialize

    { 

BaseScheduleControl DataGridView控制项,为了节省时间,设立键盘访问和辅助功能。网格对象类型HiddenGrid,扩展的DataGridView但重写的OnPaint和OnPaintBackground事件,使该控件是不可见的的。网格是暴露的子控件作为AppointmentGrid属性。
internal class HiddenGrid : DataGridView

{

    protected override void OnPaintBackground(PaintEventArgs pevent)

    {

        //Don't paint anything

    }

    protected override void OnPaint(PaintEventArgs e)

    {

        //Don't paint anything

    }

}

VisualStyleRenderer是用来拿起当前的Windows主题和颜色显示。如果禁用视觉样式,经常使用Windows颜色。 RendererCache类,油漆的日子里,他们的头衔的任命的一切,包括所有的渲染操作都包裹起来。 RendererCache举行了一系列的IRenderer对象是对象,可以绘制文本或边界(绘控件的一切基本上是一箱)箱。
internal class RendererCache

{

    //...

    private readonly IRenderer bigHeaderRenderWrap = null;

    private readonly IRenderer headerRenderWrap = null;

    private readonly IRenderer headerRenderSelWrap = null;

    private readonly IRenderer appointmentRenderWrap = null;

    private readonly IRenderer appointmentRenderSelWrap = null;

    private readonly IRenderer controlRenderWrap = null;

    private readonly IRenderer bodyRenderWrap = null;

    private readonly IRenderer bodyLightRenderWrap = null;

IRenderer有不同的实现,取决于是否启用视觉样式。如果代码是与视觉样式运行打开,将初始化一个头IRenderer如下(VisualStyleWrapper实现IRenderer):
        private readonly VisualStyleRenderer headerRender = null;

        private readonly VisualStyleElement headerElement = 

		VisualStyleElement.ExplorerBar.NormalGroupHead.Normal;

 //...

        headerRender = new VisualStyleRenderer(headerElement);

        headerRenderWrap = new VisualStyleWrapper

		(headerRender, SystemPens.ControlDarkDark);

但是,如果视觉样式被关闭,一个简单的IRenderer实施所谓NonVisualStyleWrapper将使用。 NonVisualStyleWrapper只是使用系统颜色刷,也许有点梯度补上呈现天的控制和任命。
headerRenderWrap = new NonVisualStyleWrapper(SystemColors.ControlText, 

        SystemBrushes.ControlText, 

        SystemColors.Control, 

        SystemBrushes.Control, 

        SystemColors.ControlLightLight, 

        SystemBrushes.ControlLightLight, 

        SystemPens.ControlText);

       ((NonVisualStyleWrapper)headerRenderWrap).NoGradientBlend=true;

RendererCache是​​一个单独的,是由所有三个控件在OnPaint事件。以下是它是如何用来绘制了一天一个标题框的样本。
RendererCache.Current.Header.DrawBox

(e.Graphics, Font, day.TitleBounds, day.FormattedName);

速度在应用程序的设计首要考虑的,所以没有多使用事件。同样,一天的约会项目没有控制自己 - 这将是缓慢呈现。
天/小时和任命名单,而不是使用大量的控制他们的屏幕房地产一击计算的,而且都是由父续画。天包裹在DayRegion对象,其中包含的一天,它的边界的名称。任命包裹起来AppointmentRegion对象,其中包含任用和其边界。 IRegion接口定义的共同财产 - 所有这些地区的边界。
internal interface IRegion

{

    Rectangle Bounds { get; set; }

}

日和小时区域的大小和形状是想出的CalculateTimeSlotBounds方法。这种方法被称为从OnPaint中设置为假(此属性设置为false的情况下,如已控制大小或显示的日期已经改变时)只有当财产BoundsValidTimeSlot。它是在所有三个控件覆盖,因为这三个国家都不同的布局天。
protected override void CalculateTimeSlotBounds(Graphics g)

的大小和形状的任命是想出的CalculateAppointmentBounds方法。这将确保所有的约会融入其拥有的日或小时,如果可能的话,并处理任何其他计算重叠等。这种方法被称为从OnPaint中设置为假(此属性设置为false的情况下,如已控制大小或委任名单已经改变时)只有当财产BoundsValidAppointment。
protected override void CalculateAppointmentBounds(Graphics g)

控制不包括创建/移动/编辑约会默认对话框,但示范项目包括连接这三个事件的样本对话框。未来的增强功能
在当前版本中缺少的功能:其它更多的东西上控制应在属性配置支持为全日制或多个天任命 工具提示,当您将鼠标悬停在预约(显示完整的主题)XP中,高对比度模式下,高DPI支持DayScheduleControl不支持周末,预约小时,或滚动控制没有根据屏幕阅读器进行测试,在DataGridView可能没有为它设置的属性是可读DayScheduleControl处理重叠的约会,但它使用的数学不是很好时隙导航/键盘或鼠标选择更好地突出当前的一天历史初始版本

回答

评论会员:clprogrammer 时间:2012/01/27
伟大的工作!易于定制
评论会员:。金正日多哥 时间:2012/01/27
太好了! - 书签
评论会员:!包斯塔基 时间:2012/01/27
爱你的委任名单
雷斯塔基
访问此有限公司
英国考文垂
评论会员:maq_rohit 时间:2012/01/27
尼斯努力
评论会员:会员7909798 时间:2012/01/27
感谢分享 - 我一直在工作类似的东西和你一样,我还没有得到周围,以工具提示。如果您在以后的版本添加工具提示,我将真正感兴趣的