Appointments can be created using the Scheduler for WinForms. This walkthrough guides you on how to customize the existing appointment form. For example, here we demonstrate how to add a custom button and uncheck the reminder checkbox by overriding the existing appointment form.
Define temporary variables to determine whether an appointment form is being used. The following code checks if an appointment form is used to create or modify an appointment.
C# |
コードのコピー |
---|---|
// 予定ボックスを予定の作成または変更に使用するかどうかを決定するフラグを指定します bool newEditingStatus = false; // 変更される予定を参照します C1.Schedule.Appointment currentAppointment; // ユーザー定義の予定フォームを参照します C1.Win.Schedule.Forms.AppointmentForm _customAppointmentForm; |
Observe that the existing Appointment form is a Windows Form. Therefore, to customize or update the existing appointment form, we can implement the code below through either the BeforeAppointmentCreate or BeforeAppointmentShow events. The below code illustrates implementing the new Appointment form using the BeforeAppointmentCreate event.
C# |
コードのコピー |
---|---|
private void c1Schedule1_BeforeAppointmentCreate(object sender, C1.Schedule.CancelAppointmentEventArgs e) { e.Cancel = true; currentAppointment = new C1.Schedule.Appointment(); currentAppointment.Start = this.c1Schedule1.SelectedInterval.Start; currentAppointment.End = this.c1Schedule1.SelectedInterval.End; this.c1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(currentAppointment); _customAppointmentForm = new C1.Win.Schedule.Forms.AppointmentForm(this.c1Schedule1, currentAppointment); _customAppointmentForm.FormClosing += CustomAppointmentForm_FormClosing; // 現在のボックスが新しい予定または予定の変更のために開くかどうかを定義します newEditingStatus = true; ModifyForm(_customAppointmentForm); _customAppointmentForm.ShowDialog(this); } |
The below code shows creating the new Appointment form using BeforeAppointmentShow event.
C# |
コードのコピー |
---|---|
private void c1Schedule1_BeforeAppointmentShow(object sender, CancelAppointmentEventArgs e) { e.Cancel = true; this.c1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(e.Appointment); _customAppointmentForm = new C1.Win.Schedule.Forms.AppointmentForm(this.c1Schedule1, e.Appointment); _customAppointmentForm.FormClosing += CustomAppointmentForm_FormClosing; ModifyForm(_customAppointmentForm); _customAppointmentForm.ShowDialog(this); } |
The next step defines the method to modify the appointment form. The code below checks the number of controls present on the form and adds a new button to the list of controls available on the form.
C# |
コードのコピー |
---|---|
public void ModifyForm(C1.Win.Schedule.Forms.AppointmentForm _appform) { // コントロールをループして変更を行います for (int i = _appform.Controls.Count - 1; i >= 0; i--) { Control c = _appform.Controls[i]; if (c.GetType() == typeof(Panel)) { for (int j = c.Controls.Count - 1; j >= 0; j--) { Control d = c.Controls[j]; if (d.GetType() == typeof(CheckBox)) { // 新しい予定を作成するときにリマインダーのチェックボックスをオフにします if (d.Name == "chkReminder") { if (newEditingStatus == true) { ((CheckBox)d).Checked = false; } } } } } else if (c.GetType() == typeof(ToolStrip)) { // 新しいカスタムボタンを追加します if (c.Name.Equals("toolStrip1")) { ToolStripButton btn = new ToolStripButton(); btn.Text = "Custom Button"; btn.Click += CustomButton_Click; ((ToolStrip)c).Items.Add(btn); } for (int j = 0; j < ((ToolStrip)c).Items.Count; j++) { ToolStripItem d = ((ToolStrip)c).Items[j]; if (d.GetType() == typeof(ToolStripButton)) { if (d.Name == "btnSave") { ((ToolStripButton)d).Click += SaveButton_Click; } } } } } } |
For the custom button that was added in the previous step, we will add a handler event. The code below displays a message box when the new custom button is clicked.
C# |
コードのコピー |
---|---|
private void CustomButton_Click(object sender, EventArgs e) { if (currentAppointment != null) { MessageBox.Show("This is a new button Action box"); } } |
You can save the appointment created through the save button available on the Appointment form using the code below.
C# |
コードのコピー |
---|---|
private void SaveButton_Click(object sender, EventArgs e) { ToolStripButton button = (ToolStripButton)sender; Appointment app = ((C1.Win.Schedule.Forms.AppointmentForm)button.Owner.FindForm()).Appointment; c1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(app); } |
You can also reset the appearance of the new Appointment form by resetting the temporary variable (flag value) set in the first step of this walkthrough as illustrated in the code below.
C# |
コードのコピー |
---|---|
public void CustomAppointmentForm_FormClosing(object sender, FormClosingEventArgs e) { newEditingStatus = false; } |