ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using HotelPms.Share.Util;
using HotelPms.Share.Windows.Component;
using HotelPms.Share.Windows.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace HotelPms.Share.Windows.Tool
{
    public partial class CalendarSelectorOne : FormBase
    {
        public DateTime SelDate { get; set; } = DateTime.Now;
        public Control OwnerControl { get; set; } = null;
 
        public CalendarSelectorOne(Control obj)
        {
            InitializeComponent();
            OwnerControl = obj;
        }
 
        private void Calendar1_DateSelect(object sender, CalendarEventArgs e)
        {
            SelDate = calendar1.Value;
            OwnerControl.Text = calendar1.Text;
            this.DialogResult = DialogResult.OK;
        }
 
        private void CalendarSelector_Load(object sender, EventArgs e)
        {
            calendar1.Value = CConvert.ToDateTime(OwnerControl.Text);
            //如果要将Control1(例如Label1或者Button1)上的点(x,y)转换成屏幕上的点(x1,y1),那么就调用Control1.PointToScreen。
            //反之,如果要将屏幕的(x1,y1)变成控件上的(x,y),那么就调用Control1.PointToClient。
            //eg1:求Button1的左上角在屏幕上的位置。
            //Point p = new Point(0, 0);     //   0,0   是左上角
            //p = Button1.PointToScreen(p);
            Point location = OwnerControl.PointToScreen(new Point(0, 0));
            location = new Point(location.X -1,location.Y + OwnerControl.Height - 2);
            Screen currentScreen = Screen.FromControl(OwnerControl);
            if (location.X + this.Width > currentScreen.WorkingArea.X + currentScreen.WorkingArea.Width) { location.X = currentScreen.WorkingArea.X + currentScreen.WorkingArea.Width - this.Width; }
            if(location.Y+ this.Height > currentScreen.WorkingArea.Y + currentScreen.WorkingArea.Height) { location.Y -= (currentScreen.WorkingArea.Y + OwnerControl.Height - 2 + this.Height); }
            this.Location = location;
        }
 
        public static DialogResult Execute(Control obj)
        {
            using (CalendarSelectorOne form = new CalendarSelectorOne(obj))
            {
                return form.ShowDialog();
            }
        }
 
        private void Calendar1_DayCellFormat(object sender, CalendarEventArgs e)
        {
            if (e.DateValue.ToString("MMdd") == "0101") { e.Holiday = "元旦"; }
        }
    }
}