本文整理汇总了C#中System.Windows.Forms.MonthCalendar.SetDate方法的典型用法代码示例。如果您正苦于以下问题:C# MonthCalendar.SetDate方法的具体用法?C# MonthCalendar.SetDate怎么用?C# MonthCalendar.SetDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.MonthCalendar
的用法示例。
在下文中一共展示了MonthCalendar.SetDate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: control_MouseDown
private void control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ControlFactory factory = ControlFactory.Instance;
if (e.Button == MouseButtons.Left)
{
Field field = factory.GetAssociatedField((Control)sender);
if (field != null)
{
control = (Control)sender;
if (field is DateField || field is DateTimeField)
{
if (!factory.IsPopup)
{
MonthCalendar customMonthCalendar = new MonthCalendar();
customMonthCalendar.DateSelected += new DateRangeEventHandler(customMonthCalendar_DateSelected);
customMonthCalendar.Size = new Size(226, 160);
int panelbottom = control.Parent.Bottom;
int top = control.Location.Y; int right = control.Parent.Right; int left = control.Left;
if (panelbottom - top > 185)//checking to see if the Datefield at the bottom of the canvas
{
if (right - left < 228)//if field is at the right most part of the canvas.
customMonthCalendar.Location = new Point(right - 230, top + 25);
else
customMonthCalendar.Location = new Point(control.Location.X - 10, top + 25);
}
else//if the datefield is very bottom of the canvas and no enough room for popup.
if (right - left < 228) //if field is at the right and bottom most part of the canvas.
customMonthCalendar.Location = new Point(right - 230, top - 165);
else
customMonthCalendar.Location = new Point(control.Location.X - 10, control.Top - 165);
try
{
control.Parent.Controls.Add(customMonthCalendar);
DateTime datetime ;
bool isdatetimeparse= DateTime.TryParse(control.Text, out datetime);
if (isdatetimeparse)
customMonthCalendar.SetDate(datetime);
customMonthCalendar.Visible = true;
customMonthCalendar.BringToFront();
factory.IsPopup = true;
}
catch (Exception ex)
{
}
}
}
}
}
}
示例2: DateChangedEventTest
public void DateChangedEventTest ()
{
MonthCalendar myCalendar = new MonthCalendar ();
myCalendar.Tag = false;
myCalendar.DateChanged += new DateRangeEventHandler (DateChangedEventHandler);
myCalendar.SetDate (DateTime.Today.AddDays (72));
Assert.AreEqual (true, (bool) myCalendar.Tag, "#01");
}
示例3: PopupCalendar
private void PopupCalendar(object sender, Point location)
{
ControlFactory factory = ControlFactory.Instance;
if (!factory.IsPopup)
{
DataGridView grid = (DataGridView)control;
MonthCalendar customMonthCalendar = new MonthCalendar();
customMonthCalendar.DateSelected += new DateRangeEventHandler(dataGridview_customMonthCalendar_DateSelected);
customMonthCalendar.Size = new Size(226, 160);
int panelbottom = ((Control)sender).Parent.Bottom; int panelright = ((Control)sender).Parent.Right;
int top = grid.GetCellDisplayRectangle(grid.SelectedCells[0].ColumnIndex, grid.SelectedCells[0].RowIndex, true).Y;
int x = grid.GetCellDisplayRectangle(grid.SelectedCells[0].ColumnIndex, grid.SelectedCells[0].RowIndex, true).X;
if (panelbottom - grid.Top > 165)
{
if(panelright-grid.Left<228)
customMonthCalendar.Location = new Point((grid.Location.X + x) - 226, grid.Location.Y + top + 25);
else
customMonthCalendar.Location = new Point((grid.Location.X + x) - 10, grid.Location.Y + top + 25);
}
else
if (panelright - grid.Left < 228)
customMonthCalendar.Location = new Point((grid.Location.X + x) - 226, grid.Location.Y + top + 25);
else
customMonthCalendar.Location = new Point((grid.Location.X + x) - 10, (grid.Location.Y + top) - 165);
((Control)sender).Parent.Controls.Add(customMonthCalendar);
DateTime datetime;
bool isdatetimeparse = DateTime.TryParse(grid.SelectedCells[0].Value.ToString(), out datetime);
if (isdatetimeparse)
customMonthCalendar.SetDate(datetime);
customMonthCalendar.Visible = true;
customMonthCalendar.BringToFront();
factory.IsPopup = true;
}
}
示例4: calender
public static int calender(OptsType opts, ArgsType args)
{
Form f = new Form();
Panel p = new Panel();
p.Height = 24;
p.Dock = DockStyle.Bottom;
f.Controls.Add(p);
Button b1 = new Button();
b1.DialogResult = DialogResult.OK;
b1.Dock = DockStyle.Fill;
b1.Text = "&OK";
p.Controls.Add(b1);
int year = DateTime.Now.Year;
if (opts.ContainsKey("year")) {
int val;
if (int.TryParse(opts["year"], out val)) {
year = val;
}
}
int month = DateTime.Now.Month;
if (opts.ContainsKey("month")) {
int val;
if (int.TryParse(opts["month"], out val)) {
month = val;
}
}
int day = DateTime.Now.Day;
if (opts.ContainsKey("day")) {
int val;
if (int.TryParse(opts["day"], out val)) {
day = val;
}
}
MonthCalendar mc = new MonthCalendar();
mc.CalendarDimensions = new Size(1, 1);
mc.MaxSelectionCount = 42;
mc.SetDate(new DateTime(year, month, day));
f.Controls.Add(mc);
f.Text = "fwfw calender";
if (opts.ContainsKey("title")) {
f.Text = opts["title"];
}
f.MaximizeBox = false;
f.FormBorderStyle = FormBorderStyle.FixedDialog;
f.StartPosition = FormStartPosition.CenterScreen;
f.ClientSize = mc.Size;
f.Height = f.Height + p.Height;
if (f.ShowDialog() != DialogResult.OK) {
return 1;
}
var start = mc.SelectionStart.ToShortDateString().Replace('/', '-');
var end = mc.SelectionEnd.ToShortDateString().Replace('/', '-');
Console.Out.WriteLine(start);
if (start != end) {
Console.Out.WriteLine(end);
}
return 0;
}