How do I get the width of the AppointmentElement in the AppointmentFormatting Event?
e.AppointmentElement.Size returns nothing
e.AppointmentElement.Bounds returns 0,0,0,0
I am trying to place an image at a specific time point within the appointment element.
Is there an easier way to accomplish this?
Thanks,
4 Answers, 1 is accepted
Thank you for writing.
Depending on the current view and whether the exact time rendering is enabled, the AppointmentElement may have different size. When the AppointmentFormatting event is fire for the first time, the visual appointment element is not sized yet. However, at each next firing of the AppointmentFormatting after the form has been loaded, you can get the AppointmentElement.ControlBoundingRectangle or Size property.
In order to achieve your goal and place an image inside the event element, you can use a custom AppointmentElement and replace the default one in the SchedulerElementProvider. Here is demonstrated a sample approach. Feel free to modify it in a way which suits your requirement best:
public
Form1()
{
InitializeComponent();
this
.radScheduler1.ElementProvider =
new
CustomElementProvider(
this
.radScheduler1);
this
.radScheduler1.Appointments.Add(
new
Appointment(DateTime.Now, TimeSpan.FromHours(2),
"Business meeting"
));
}
public
class
CustomAppointmentElement : AppointmentElement
{
public
CustomAppointmentElement(RadScheduler scheduler, SchedulerView view, IEvent appointment) :
base
(scheduler, view, appointment)
{
}
LightVisualElement lve =
new
LightVisualElement();
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
lve.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this
.Children.Add(lve);
}
public
override
void
Synchronize()
{
base
.Synchronize();
lve.Text =
this
.Appointment.Summary;
lve.Image = Properties.Resources.calendar;
}
public
override
void
DrawEventText(Telerik.WinControls.Paint.IGraphics graphics)
{
//do no draw the default text and use the one in the LightVisualElement
//base.DrawEventText(graphics);
}
}
public
class
CustomElementProvider : SchedulerElementProvider
{
public
CustomElementProvider(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);
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Dess
Telerik
Thanks for the reply. I will give the code a try and see if it gets me where I need to go.
What I am really needing in the ability to calculate the correct time position within the appointmentelement so that I can place the image there.
i.e. If Tom is working a 9:00 AM to 6:00 PM shift (appointmentelement) and has a Dr's appointment on that day at 2:00 PM, then I want to place that image on his appointmentelemet at the 2:00 PM mark.
What is the best way to approach this?
Sorry, forgot to mention that I am using the timeline view.
Attached is a sample of what I am trying to do.
Thanks,
Thank you for writing back.
It is not recommended to use a single Appointment from 9:00 AM to 6:00 PM to indicate the work time for a person because that way it is not possible to display in a convenient way the other events during the day. RadScheduler offers work time for its DayView to specify a predefined range of hours, which can be specified within the timeline to make it easier for end-users to carry out scheduling. Please refer to the Scheduler >> Day View help article >> Changing the work time section. Thus, you can add an Appointment from 2 PM for the Dr's meeting and use the RadScheduler control by its designed usage.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik