Posted 8 July 2021, 11:46 am EST
Hi,
Is it possible to change the ForeColor of a single C1Schedule appointment programmatically ? If so, could you please provide a small C# sample ?
Thanks in advance,
Stephan
Forums Home / ComponentOne / WinForms Edition
Posted by: SHanau on 8 July 2021, 11:46 am EST
Posted 8 July 2021, 11:46 am EST
Hi,
Is it possible to change the ForeColor of a single C1Schedule appointment programmatically ? If so, could you please provide a small C# sample ?
Thanks in advance,
Stephan
Posted 8 July 2021, 9:01 pm EST
Hi,
Just to clarify: I want to change the forecolor of an appointment depending on a field value of the underlying datarow.
Thanks in advance.
Posted 9 July 2021, 12:09 am EST
Hi,
You can handle the BeforeAppointmentFormat event and then set the ForeColor conditionally. You can access the Appointment using the Appointment property of the BeforeAppointmentFormatEventArgs and then set the ForeColor property of the BeforeAppointmentFormatEventArgs to set the forecolor of the appointment being formatted.
private void C1Schedule1_BeforeAppointmentFormat(object sender, C1.Win.C1Schedule.BeforeAppointmentFormatEventArgs e)
{
if (e.Appointment.AllDayEvent)
{
e.ForeColor = Color.Red;
}
else {
e.ForeColor = Color.Blue;
}
}
Regards
Avnish
Posted 9 July 2021, 4:29 am EST
Hi Avnish,
Thanks for your quick response. I’m currently using version 4.20202.438 of C1Schedule.
Unfortunately it seems as if there is no ForeColor property included in C1.Win.C1Schedule.BeforeAppointmentFormatEventArgs.
Please advise. Thanks in advance,
Stephan
Posted 11 July 2021, 11:33 pm EST
Hi,
NET 4.0 version of controls has been in maintenance mode for a long time and no enhancements or improvements are being added to it. We suggest you upgrade to the NET 4.5.2 version of C1 controls to enjoy regular fixes and enhancements. You can upgrade to 4.5.20202.438 as it has the ForeColor property included in C1.Win.C1Schedule.BeforeAppointmentFormatEventArgs.
Support Notice: https://www.grapecity.com/forums/winforms-edition/net-40-and-20-support-noti_1
Regards
Avnish
Posted 12 July 2021, 4:35 am EST
Hi,
another solution is to use HTML formatting.
We use this code (the appointment text is wrapped in a “span” element):
appointment.Subject = "<span style='color: #" + mycolor.ToArgb().ToString("x") + "'>Appointment text</span>";
Best regards
Wolfgang
Posted 13 July 2021, 12:07 am EST
Hi,
You can also use the workaround suggested by Wolfgang. You can handle the BeforeAppointmentFormat event and then set the appointment text as shown in the following code:
private void C1Schedule1_BeforeAppointmentFormat(object sender, C1.Win.C1Schedule.BeforeAppointmentFormatEventArgs e)
{
if (e.Appointment.AllDayEvent)
{
e.Text = "<p style=color:red>" + e.Text + "</>";
}
else {
e.Text = "<p style=color:blue>" + e.Text + "</>";
}
}
Although, we would still recommend you to upgrade to the NET4.5.2 version of C1 controls to take advantage of improvements and fixes and regular updates.
Regards
Avnish
PS:
Thank You Wolfgang for the suggestion.
Posted 17 July 2021, 8:15 am EST
Hi Avnish, Hi Wolfgang,
Thank you very much for your support. I had to use your suggested workaround as I’m currently not able to upgrade my project to NET4.5.2 as I use C1RibbonForm heavily and haven’t got the time to convert it to NET4.5.2 as I would have to implement a ThemeManager on every form.
So I tried to upgrade at least the C1Schedule control to NET4.5.2. However I had to revert to NET4.0 because I couldn’t figure out how to have C1.Win.4 and C1.Win.4.5.2 in the same project and distinct between some objects which are in both classes and have got the same name.
Thanks again,
Stephan
Posted 19 July 2021, 12:46 am EST
Hi Stephan,
Using both DLLs in the same project might result in conflicts. Since you are unable to upgrade to NET4.5.2 for now, you can continue with the workaround and let us know if you face any issues.
Regards.
Avnish
Posted 19 July 2021, 3:51 am EST
Hi Stephan,
The C1Themes change is not necessary in 4.5.2, you can continue to use the ribbon VisualStyles as long as you don’t migrate the ribbons from “C1.Win.C1Ribbon” to “C1.Win.Ribbon” dll.
Best regards
Wolfgang
Posted 19 July 2021, 5:35 am EST
Hi,
Thank you for the suggestion, Wolfgang.
Yes, you can use the old C1Ribbon in NET4.5.2 but if you are upgrading to NET4.5.2 then we would recommend you use the new C1Ribbon so that you can get regular fixes, improvements, and other updates.
Regards.
Avnish