如何生成C#.NET Windows应用程序日历 [英] How to generate Calendar in c#.net windows application

查看:271
本文介绍了如何生成C#.NET Windows应用程序日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要生成的C#.NET日历进入日常attendance.I已经使用jQuery的日历在网上类似的目的。有用来创建日历控件并获得点击事件标记,并在显示值的方式。

I want to Generate Calendar in c#.net to enter daily attendance.I have used jquery calendar for similar purpose in web. Is there any ways to create calendar control and get click event to mark and display values in that.

感谢

示例图片:

推荐答案

如果你有一个预算我肯定会去喜欢的 Telerik的调度控制。这将花费$ 999集,我从来没有使用Telerik的控件之前,所以我不能推荐他们自己,而是由看起来它可能是值得的,从长远来看,如果你可以在其他项目中重用的组件。

If you have a budget I would definitely go for a commercial component like Telerik's Scheduler Control. That will cost $999 for the collection, I've never used Telerik's controls before so I can't recommend them myself but by the looks it could be well worth it in the long run if you can reuse the components in other projects.

如果这不是一种选择,因为东西例如你将是相当容易翻车自己一样简单。我的工作主要是在WinForms的,所以这是我将如何着手建立形式:

If that isn't an option, something as simple as your example would be fairly easy to roll yourself. I mainly work in WinForms so this is how I would go about building the form:


  1. 创建一个自定义的控件来显示任何一天。您需要在一个月的日子右上角的标签和标签,以显示当天的文本(输入/输出次)。也许添加边框。

  2. 创建窗体或控件将包含日历

  3. 添加停靠到顶部的月份和年份控件工具条。使用组合框或下拉按钮。

  4. 添加薄面板停靠到顶部,添加标签为天。决定你想要每一列是基于该标签定位的宽度。

  5. 添加 FlowLayoutPanel的并设置码头填写。这将包含天的控制,这将流向从左到右,从上到下。

  1. Create a custom control to display any given day. You will need a label in the top corner for the day of month, and a label to display the text for the day (the In/Out times). Maybe add a border.
  2. Create a form or control that will contain the calendar
  3. Add a toolstrip docked to the top with your month and year controls. Use a combo box or drop-down button.
  4. Add a thin panel docked to the top and add labels for the days. Decide on the width you want each column to be and position the labels based on that.
  5. Add a FlowLayoutPanel and set Dock to Fill. This will contain the 'day' controls, which will flow left to right, top to bottom.

现在你需要将工作代码,而不是设计师。这或许可以在构造函数中完成,的Page_Load 处理程序,或者某个地方的时候月/年设置(或初始化)被调用:

Now you need to be working in code, not the designer. This could probably be done in the constructor, the Page_Load handler, or somewhere that gets called when the month/year is set (or initialised):


  1. 足够的空板的 FlowLayoutControl 垫加入了一个月的开始。你可以找到多少与新添加的日期时间(年,月,1).DayOfWeek 找一天,在第一个月的落在了。空面板应该被设置为相同的大小作为天的控制。

  2. 添加控制到 FlowLayoutControl 为每一天的一个月。使用 DateTime.DayInMonth(年,月)来发现在选定月份的天数,并设置每个天控制与日期(也可能是在/出的数据)为您添加它。

  3. 现在,有填充和边框上的天控制和填充面板播放,直到一切看起来正确的。您可以添加一些测试天的控制和面板在设计师那里测试布局并调用 flowLayoutControl.Items.Clear()设置代码。

  1. Add enough empty panels to the FlowLayoutControl to pad out the start of the month. You can find out how many to add with new DateTime(year, month, 1).DayOfWeek to find the day that the first of the month falls on. The empty panels should be set to the same size as the 'day' control.
  2. Add a day control to the FlowLayoutControl for each day in the month. Use DateTime.DayInMonth(year, month) to find the number of days in the selected month, and set each 'day' control up with the date (and probably the in/out data) as you're adding it.
  3. Now play with padding and borders on the 'day' controls and padding panels until everything looks right. You can add some test 'day' controls and panels in the designer to test layouts there and just call flowLayoutControl.Items.Clear() in the setup code.

这应该导致可以动态显示任何一个月的控制。要添加考勤编辑功能,设置了点击无论是在天控制或日历控件本身处理器(当你加入天控件在 FlowLayoutControl ,并打开一个模式表单编辑或添加/渐暗时间选定日期。

That should result in a control that can dynamically display any month. To add the attendance editing feature, set up a Click handler either in the 'day' control or in the calendar control itself (when you're adding the 'day' controls to the FlowLayoutControl, and open up a modal form to edit or add the in/out times for the selected day.

如果你想一天控制动态调整注册了包含控件的调整事件,并设置宽度和每一天的控制高度 Math.Floor (control.Width / 7)(7天宽)和 Math.Floor(control.Height / 5)(五个周最高)什么相似。

If you wanted the day controls to resize dynamically register for the containing control's Resize event and set the width and height of each day control to Math.Floor(control.Width / 7) (seven days wide) and Math.Floor(control.Height / 5) (five weeks high) or something similar.

这篇关于如何生成C#.NET Windows应用程序日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆