Unplanned
Last Updated: 25 May 2023 13:36 by ADMIN
Paul Dell
Created on: 25 May 2023 13:25
Category: Scheduler/Reminder
Type: Feature Request
1
RadScheduler: Add public property to control the status width for the AppointmentElement

This width is 6px by default and it doesn't offer convenient API for customizing it:

1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 25 May 2023 13:36

Hello, Paul,

Thank you for bringing this request to our attention. The possible solution that I can suggest is to use the following custom rendering where the status rectangle is actually being rendered: 

        public Form1()
        {
            InitializeComponent();
            this.radScheduler1.ElementProvider = new MyElementProvider(this.radScheduler1);
        }


        public class MyElementProvider : SchedulerElementProvider
        {
            public MyElementProvider(RadScheduler scheduler)
                : base(scheduler)
            {
            }

            protected override T CreateElement<T>(SchedulerView view, object context)
            {
                if (typeof(T) == typeof(AppointmentElement))
                {
                    return new CustomAppointmentElement(this.Scheduler, view, (IEvent)context) as T;
                }

                return base.CreateElement<T>(view, context);
            }
        }

        public class CustomAppointmentElement : AppointmentElement
        {
            public CustomAppointmentElement(RadScheduler scheduler, SchedulerView view, IEvent appointment)
                : base(scheduler, view, appointment)
            {
                fi.SetValue(this, 40);
            }
            FieldInfo fi = typeof(AppointmentElement).GetField("appointmentTypeAreaWidth", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            public override void DrawDefaultBackground(Telerik.WinControls.Paint.IGraphics graphics)
            {
                ElementShape appShape = this.Shape;

                if (appShape == null && this.Scheduler != null && this.Scheduler.SchedulerElement.AppointmentShape != null)
                {
                    appShape = this.Scheduler.SchedulerElement.AppointmentShape;
                }

                if (appShape == null)
                {
                    appShape = new RoundRectShape(0);
                }

                appShape = RTLTranslateRoundRectShape(appShape);

                int shadowWidth = (int)typeof(AppointmentElement).GetField("shadowWidth",
                            System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this);

              
                int appointmentTypeAreaWidth = (int)fi.GetValue(this);
                Rectangle paintRect = new Rectangle(this.Bounds.X, this.Bounds.Y, this.Bounds.Width - shadowWidth, this.Bounds.Height - shadowWidth);
                Brush statusBrush = GetStatusBrush(this.Appointment.StatusId);

                if (statusBrush != null)
                {
                    GraphicsPath path = appShape.CreatePath(paintRect);
                    ((Graphics)graphics.UnderlayGraphics).FillPath(statusBrush, path);
                    path.Dispose();
                    path = null;
                    statusBrush.Dispose();
                }

                paintRect = new Rectangle(this.Bounds.X + appointmentTypeAreaWidth, this.Bounds.Y, this.Bounds.Width -
                                   shadowWidth - appointmentTypeAreaWidth, this.Bounds.Height - shadowWidth);

                if (this.RightToLeft)
                {
                    paintRect = new Rectangle(this.Bounds.X, this.Bounds.Y, this.Bounds.Width - shadowWidth -
                                   appointmentTypeAreaWidth, this.Bounds.Height - shadowWidth);
                }

                using (GraphicsPath path = appShape.CreatePath(paintRect))
                {
                    Color[] colors = new Color[] { this.BackColor, this.BackColor2 };
                    float[] colorOffsets = new float[] { 0f, 1f };

                    if (GradientStyle == GradientStyles.Solid)
                    {
                        colors[1] = BackColor;
                    }

                    graphics.FillPath(colors, colorOffsets, this.GradientAngle, this.GradientPercentage,
                        this.GradientPercentage2, paintRect, path);
                }
            }

            private ElementShape RTLTranslateRoundRectShape(ElementShape shape)
            {
                RoundRectShape roundShape = shape as RoundRectShape;
                if (roundShape == null)
                {
                    return shape;
                }

                if (!this.RightToLeft || shape == null)
                {
                    return shape;
                }

                RoundRectShape newShape = new RoundRectShape();
                newShape.Radius = roundShape.Radius;
                newShape.BottomLeftRounded = roundShape.BottomRightRounded;
                newShape.BottomRightRounded = roundShape.BottomLeftRounded;
                newShape.TopLeftRounded = roundShape.TopRightRounded;
                newShape.TopRightRounded = roundShape.TopLeftRounded;

                return newShape;
            }

            private Brush GetStatusBrush(int statusId)
            {
                int appointmentTypeAreaWidth =  (int)fi.GetValue(this);
                Rectangle rect = new Rectangle(0, 0, appointmentTypeAreaWidth, Math.Max(24, this.Bounds.Height));
                if (this.Scheduler == null || this.Appointment == null)
                    return null;

                ISchedulerStorage<IAppointmentStatusInfo> storage = this.Scheduler.GetStatusStorage();
                IAppointmentStatusInfo info = storage.GetById(statusId);

                if (info == null)
                {
                    info = storage.GetById(AppointmentStatusInfo.DefaultStatusId);
                    if (info == null)
                    {
                        return null;
                    }
                }

                if (info.Id == AppointmentStatusInfo.DefaultStatusId)
                {
                    ISchedulerStorage<IAppointmentBackgroundInfo> backgroundStorage = this.Scheduler.GetBackgroundStorage();
                    IAppointmentBackgroundInfo backgroundInfo = backgroundStorage.GetById(this.Appointment.BackgroundId);

                    if (backgroundInfo != null)
                    {
                        return new LinearGradientBrush(rect, backgroundInfo.BackColor, backgroundInfo.BackColor2, LinearGradientMode.Vertical);
                    }
                }

                switch (info.FillType)
                {
                    case AppointmentStatusFillType.Gradient:
                        return new LinearGradientBrush(rect, info.BackColor, info.BackColor2, LinearGradientMode.Horizontal);
                    case AppointmentStatusFillType.Hatch:
                        Color foreColor = info.BackColor;
                        if (info.UseAppointmentBorderHatchForeColor)
                        {
                            foreColor = this.BorderColor;
                        }
                        return new HatchBrush(HatchStyle.BackwardDiagonal, foreColor, info.BackColor2);
                    case AppointmentStatusFillType.Solid:
                        return new SolidBrush(info.BackColor);
                }

                return new SolidBrush(Color.White);
            }
        }

 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.