How to split intersected Labels in Windows Forms C#.Net?

Apr 15 2020 4:39 AM
I created this WFP application that generates Labels in certain locations in the Form to show a weekly planning based on settings from other form
 
  1. CustomLabel.Add(new Label()):  
  2. (CustomLabel[CustomLabel.Count - 1] as Label).Location = new System.Drawing.Point(117,Y(LISTPLANS[MainForm.indexplan].Subjects.ElementAt
  3. (CustomLabel[CustomLabel.Count - 1] as Label).Size = new System.Drawing.Size(97,L(LISTPLANS[MainForm.indexplan].Subjects.ElementAt(i).PSchedule.EndTime));  
  4. Controls.Add(CustomLabel[CustomLabel.Count - 1] as Control);  
 

The size and the location of the Label is relative to the starting DateTime and ending DateTime and of course the Day:

Y: for (Location.Y)
L: for (Size.Hight) 
  1. public Int32 Y(DateTime StartTime)  
  2. {  
  3.     double onehour = 19.5;  
  4.     double minute = Math.Ceiling(StartTime.Minute / 15.0) / 4.0;  
  5.     switch (StartTime.Hour)  
  6.     {  
  7.         case 6:  
  8.             return (Int32)(94 + minute * onehour);  
  9.         case 7:  
  10.             return (Int32)(114 + minute * onehour);  
  11.         case 8:  
  12.             return (Int32)(135 + minute * onehour);  
  13.         case 9:  
  14.             return (Int32)(156 + minute * onehour);  
  15.         case 10:  
  16.             return (Int32)(177 + minute * onehour);  
  17.         case 11:  
  18.             return (Int32)(197 + minute * onehour);  
  19.         case 12:  
  20.             return (Int32)(219 + minute * onehour);  
  21.         case 13:  
  22.             return (Int32)(240 + minute * onehour);  
  23.         case 14:  
  24.             return (Int32)(260 + minute * onehour);  
  25.         case 15:  
  26.             return (Int32)(280 + minute * onehour);  
  27.         case 16:  
  28.             return (Int32)(302 + minute * onehour);  
  29.         case 17:  
  30.             return (Int32)(322 + minute * onehour);  
  31.         case 18:  
  32.             return (Int32)(344 + minute * onehour);  
  33.         case 19:  
  34.             return (Int32)(366 + minute * onehour);  
  35.         case 20:  
  36.             return (Int32)(388 + minute * onehour);  
  37.         case 21:  
  38.             return (Int32)(407 + minute * onehour);  
  39.         case 22:  
  40.             return (Int32)(428 + minute * onehour);  
  41.         case 23:  
  42.             return (Int32)(449 + minute * onehour);  
  43.         case 0:  
  44.             return (Int32)(470 + minute * onehour);  
  45.         default:  
  46.             return 0;  
  47.     }  
  48. }  
  49. public Int32 L(DateTime StartTime, DateTime EndTime)  
  50. {  
  51.     return (Int32)(Y(EndTime) - Y(StartTime));  
  52. }  

I figured this out, still the problem is if the user entered a time similar to a previously reserved time the program will create a label on the old one and obviously it will hide it, same if the user set

for example:
Subject1 : from 8:00 -> 11:00 - Saturday
Subject2 : from 10:00 -> 12:00 - Saturday
The generated two Labels will be intersected with each other. I want a code that split these intersected Labels (the default width is 97) So that both will get a width of 48:
 Please consider I'm just a beginner to programming; so give me extra explanation please;