Example T579967
Visible to All Users

WinForms Scheduler - Customize the appointment flyout

This example demonstrates how to handle the following events to customize the appointment flyouts:

WinForms Scheduler - Customize the appointment flyout

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

CustomAppointmentFlyoutExample/CustomAppointmentSourceObject.cs(vb)
C#
using System; namespace CustomAppointmentFlyoutExample { class CustomAppointmentSourceObject { public DateTime StartTime { get; set; } public DateTime EndTime { get; set; } public string Subject { get; set; } public int Status { get; set; } public string Description { get; set; } public int Label { get; set; } public string Location { get; set; } public bool AllDay { get; set; } public int EventType { get; set; } public string RecurrenceInfo { get; set; } public string ReminderInfo { get; set; } public object OwnerId { get; set; } } }
CustomAppointmentFlyoutExample/CustomResourceSourceObject.cs(vb)
C#
namespace CustomAppointmentFlyoutExample { class CustomResourceSourceObject { public string Name { get; set; } public int ResID { get; set; } } }
CustomAppointmentFlyoutExample/DataHelper.cs(vb)
C#
using DevExpress.XtraScheduler; using System; using System.Collections.Generic; using System.Drawing; namespace CustomAppointmentFlyoutExample { static class DataHelper { public static Random RandomInstance = new Random(); public static List<CustomResourceSourceObject> CustomResourceCollection = new List<CustomResourceSourceObject>(); public static List<CustomAppointmentSourceObject> CustomEventList = new List<CustomAppointmentSourceObject>(); public static void InitResources(SchedulerStorage storage) { ResourceMappingInfo mappings = storage.Resources.Mappings; mappings.Id = "ResID"; mappings.Caption = "Name"; CustomResourceCollection.Add(CreateCustomResource(1, "Max Fowler", Color.PowderBlue)); CustomResourceCollection.Add(CreateCustomResource(2, "Nancy Drewmore", Color.PaleVioletRed)); CustomResourceCollection.Add(CreateCustomResource(3, "Pak Jang", Color.PeachPuff)); storage.Resources.DataSource = CustomResourceCollection; } public static CustomResourceSourceObject CreateCustomResource(int res_id, string caption, Color ResColor) { CustomResourceSourceObject cr = new CustomResourceSourceObject(); cr.ResID = res_id; cr.Name = caption; return cr; } public static void InitAppointments(SchedulerStorage storage) { AppointmentMappingInfo mappings = storage.Appointments.Mappings; mappings.Start = "StartTime"; mappings.End = "EndTime"; mappings.Subject = "Subject"; mappings.AllDay = "AllDay"; mappings.Description = "Description"; mappings.Label = "Label"; mappings.Location = "Location"; mappings.RecurrenceInfo = "RecurrenceInfo"; mappings.ReminderInfo = "ReminderInfo"; mappings.ResourceId = "OwnerId"; mappings.Status = "Status"; mappings.Type = "EventType"; GenerateEvents(CustomEventList, storage); storage.Appointments.DataSource = CustomEventList; } public static void GenerateEvents(List<CustomAppointmentSourceObject> eventList, SchedulerStorage storage) { int count = storage.Resources.Count; for (int i = 0; i < count; i++) { Resource resource = storage.Resources[i]; string subjPrefix = resource.Caption + "'s "; eventList.Add(CreateEvent(subjPrefix + "meeting", resource.Id, 2, 5, 14)); eventList.Add(CreateEvent(subjPrefix + "travel", resource.Id, 3, 6, 10)); eventList.Add(CreateEvent(subjPrefix + "talk", resource.Id, 0, 4, 16)); } } public static CustomAppointmentSourceObject CreateEvent(string subject, object resourceId, int status, int label, int sHour) { CustomAppointmentSourceObject apt = new CustomAppointmentSourceObject(); apt.Subject = subject; apt.OwnerId = resourceId; apt.StartTime = DateTime.Today.AddHours(RandomInstance.Next(12)); apt.EndTime = apt.StartTime.AddHours(RandomInstance.Next(4) + 1); apt.Status = status; apt.Label = label; return apt; } } }
CustomAppointmentFlyoutExample/Form1.cs(vb)
C#
using DevExpress.Utils.Drawing; using DevExpress.Utils.Svg; using DevExpress.XtraEditors; using DevExpress.XtraScheduler; using System; using System.Drawing; using System.IO; using System.Reflection; namespace CustomAppointmentFlyoutExample { public partial class Form1 : XtraForm { readonly FontStorage fontStorage; public Form1() { this.fontStorage = new FontStorage(); InitializeComponent(); InitializeScheduler(); } void InitializeScheduler() { DataHelper.InitResources(this.schedulerStorage1); DataHelper.InitAppointments(this.schedulerStorage1); this.schedulerControl1.Start = DateTime.Today; this.schedulerControl1.GroupType = SchedulerGroupType.Resource; #region #OptionsFlyout schedulerControl1.OptionsFlyout.SubjectAutoHeight = true; #endregion #OptionsFlyout } #region #CustomizeAppointmentFlyout void OnSchedulerControlCustomizeAppointmentFlyout(object sender, CustomizeAppointmentFlyoutEventArgs e) { e.ShowEndDate = false; e.ShowReminder = false; e.ShowLocation = true; e.SubjectAppearance.Font = fontStorage.SubjectAppearanceFont; e.Location = "N/A"; } #endregion #CustomizeAppointmentFlyout #region #CustomDrawAppointmentFlyoutSubject void OnSchedulerControlCustomDrawAppointmentFlyoutSubject(object sender, CustomDrawAppointmentFlyoutSubjectEventArgs e) { e.Handled = true; CustomDrawAppointmentFlyoutSubject(e); } void CustomDrawAppointmentFlyoutSubject(CustomDrawAppointmentFlyoutSubjectEventArgs e) { AppointmentBandDrawerViewInfoBase viewInfo = (AppointmentBandDrawerViewInfoBase)e.ObjectInfo; e.DrawBackgroundDefault(); CustomDrawAppointmentFlyoutSubject(e.Appointment, viewInfo); } void CustomDrawAppointmentFlyoutSubject(Appointment appointment, AppointmentBandDrawerViewInfoBase viewInfo) { GraphicsCache cache = viewInfo.Cache; StringFormat stringFormat = new StringFormat(viewInfo.View.Appearance.GetStringFormat()); stringFormat.Alignment = stringFormat.LineAlignment = StringAlignment.Center; try { // Draw status Rectangle statusRect = GetStatusBounds(viewInfo); cache.FillRectangle(viewInfo.View.Status.GetBrush(), statusRect); if (viewInfo.View.Status.Type == AppointmentStatusType.Free) { // Draw a warning cache.DrawImage(GetWarningIcon(new Size(statusRect.Height, statusRect.Height)), statusRect.Location); cache.DrawString("Status is unacceptable", fontStorage.StatusFont, Brushes.Red, statusRect, stringFormat); } // Draw subject cache.DrawString(appointment.Subject, fontStorage.SubjectFont, Brushes.Black, GetSubjectBounds(viewInfo), stringFormat); } finally { stringFormat.Dispose(); } } Rectangle GetSubjectBounds(AppointmentBandDrawerViewInfoBase viewInfo) { Rectangle bounds = viewInfo.Bounds; if (viewInfo.View.Status.Type == AppointmentStatusType.Free) { bounds.Offset(0, 10); } return bounds; } Rectangle GetStatusBounds(AppointmentBandDrawerViewInfoBase viewInfo) { Rectangle bounds = Rectangle.Inflate(viewInfo.Bounds, -1, -1); if (viewInfo.View.Status.Type == AppointmentStatusType.Free) { bounds.Height = 20; } else { bounds.Height = 5; } return bounds; } Image GetWarningIcon(Size size) { using (Stream stream = AppAssembly.GetManifestResourceStream("CustomAppointmentFlyoutExample.warning.svg")) { var paletteProvider = SvgPaletteHelper.GetSvgPalette(schedulerControl1.LookAndFeel, ObjectState.Selected); return SvgBitmap.FromStream(stream).Render(size, paletteProvider); } } static readonly Assembly AppAssembly = Assembly.GetExecutingAssembly(); #endregion #CustomDrawAppointmentFlyoutSubject #region #AppointmentFlyoutShowing void OnSchedulerControl1AppointmentFlyoutShowing(object sender, AppointmentFlyoutShowingEventArgs e) { e.Control = new MyFlyout(e.FlyoutData.Subject, e.FlyoutData.Start, e.FlyoutData.End); } #endregion #AppointmentFlyoutShowing private void chkBtnTooltips_CheckedChanged(object sender, EventArgs e) { if (chkBtnTooltips.Checked) { #region #AllowDisplayAppointmentFlyout schedulerControl1.OptionsCustomization.AllowDisplayAppointmentFlyout = false; schedulerControl1.OptionsView.ToolTipVisibility = ToolTipVisibility.Always; #endregion #AllowDisplayAppointmentFlyout } else { schedulerControl1.OptionsCustomization.AllowDisplayAppointmentFlyout = true; schedulerControl1.OptionsView.ToolTipVisibility = ToolTipVisibility.Never; } } private void chkBtnAppointmentFlyoutShowing_CheckedChanged(object sender, EventArgs e) { if (chkBtnAppointmentFlyoutShowing.Checked) schedulerControl1.AppointmentFlyoutShowing += OnSchedulerControl1AppointmentFlyoutShowing; else schedulerControl1.AppointmentFlyoutShowing -= OnSchedulerControl1AppointmentFlyoutShowing; } private void chkBtnCustomizeAppointmentFlyout_CheckedChanged(object sender, EventArgs e) { if (chkBtnCustomizeAppointmentFlyout.Checked) schedulerControl1.CustomizeAppointmentFlyout += OnSchedulerControlCustomizeAppointmentFlyout; else schedulerControl1.CustomizeAppointmentFlyout -= OnSchedulerControlCustomizeAppointmentFlyout; } private void chkBtnCustomDrawAppointmentFlyoutSubject_CheckedChanged(object sender, EventArgs e) { if (chkBtnCustomDrawAppointmentFlyoutSubject.Checked) schedulerControl1.CustomDrawAppointmentFlyoutSubject += OnSchedulerControlCustomDrawAppointmentFlyoutSubject; else schedulerControl1.CustomDrawAppointmentFlyoutSubject -= OnSchedulerControlCustomDrawAppointmentFlyoutSubject; } } public class FontStorage : IDisposable { readonly Font subjectFont; readonly Font statusFont; readonly Font subjectAppearanceFont; public FontStorage() { this.subjectFont = new Font("Tahoma", 10, FontStyle.Bold); this.statusFont = new Font("Tahoma", 8, FontStyle.Bold); this.subjectAppearanceFont = new Font("Arial", 24); } public void Dispose() { Dispose(true); } void Dispose(bool disposing) { if (disposing) { SubjectFont.Dispose(); StatusFont.Dispose(); SubjectAppearanceFont.Dispose(); } } public Font SubjectFont { get { return subjectFont; } } public Font StatusFont { get { return statusFont; } } public Font SubjectAppearanceFont { get { return subjectAppearanceFont; } } } }
CustomAppointmentFlyoutExample/MyFlyout.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; namespace CustomAppointmentFlyoutExample { public partial class MyFlyout : XtraUserControl { public MyFlyout() { InitializeComponent(); } public MyFlyout(string subject, DateTime start, DateTime end) { InitializeComponent(); this.labelControl1.Text = subject; this.labelControl2.Text = start.ToString(); this.labelControl3.Text = end.ToString(); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.