private void ColourPicker_Enter(object sender, EventArgs e)
        {
            if (Forms.Main.Instance.ActiveCalendarProfile.UseGoogleCalendar == null || string.IsNullOrEmpty(Forms.Main.Instance.ActiveCalendarProfile.UseGoogleCalendar.Id))
            {
                OgcsMessageBox.Show("You need to select a Google Calendar first on the 'Settings' tab.", "Configuration Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ToolTip loading = new ToolTip();

            try {
                GoogleOgcs.EventColour.Palette currentSelection = null;

                if (GoogleOgcs.Calendar.IsInstanceNull || !GoogleOgcs.Calendar.Instance.ColourPalette.IsCached())
                {
                    loading.SetToolTip(this, "Retrieving colours from Google...");
                    loading.ShowAlways   = true;
                    loading.InitialDelay = 0;
                    loading.Show("Retrieving colours from Google...", this, this.FindForm().PointToClient(this.Parent.PointToScreen(this.Location)));

                    GoogleOgcs.Calendar.Instance.ColourPalette.Get();
                    currentSelection = (GoogleOgcs.EventColour.Palette)SelectedItem;

                    loading.Hide(this);
                }
                if (Items.Count != GoogleOgcs.Calendar.Instance.ColourPalette.ActivePalette.Count)
                {
                    while (Items.Count > 0)
                    {
                        Items.RemoveAt(0);
                    }
                    AddPaletteColours(true);
                }

                foreach (GoogleOgcs.EventColour.Palette pInfo in Items)
                {
                    if (pInfo.Id == currentSelection?.Id)
                    {
                        SelectedItem = pInfo;
                        break;
                    }
                }
            } catch (System.Exception ex) {
                OGCSexception.Analyse("ColourPicker_Enter()", ex);
            } finally {
                loading.Hide(this);
                loading.RemoveAll();
            }

            if (Items.Count > 1 && SelectedIndex == -1)
            {
                SelectedIndex = 0;
            }
        }
 public static Outlook.OlCategoryColor GetClosestCategory(GoogleOgcs.EventColour.Palette basePalette)
 {
     try {
         var colourDistance = Colours.Select(x => new { Value = x, Diff = GoogleOgcs.EventColour.GetDiff(x.Value, basePalette.RgbValue) }).ToList();
         var minDistance    = colourDistance.Min(x => x.Diff);
         return(colourDistance.Find(x => x.Diff == minDistance).Value.Key);
     } catch (System.Exception ex) {
         log.Warn("Failed to get closest Outlook category for " + basePalette.ToString());
         OGCSexception.Analyse(ex);
         return(Outlook.OlCategoryColor.olCategoryColorNone);
     }
 }
        public void ColourPicker_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            ComboBox cbColour = sender as ComboBox;

            if (e == null || e.Index < 0 || e.Index >= cbColour.Items.Count)
            {
                return;
            }

            // Get the colour
            GoogleOgcs.EventColour.Palette colour = (GoogleOgcs.EventColour.Palette)Items[e.Index];
            ColourCombobox.DrawComboboxItemColour(cbColour, new SolidBrush(colour.RgbValue), colour.Name, e);
        }