How can I make my notification windows more toast like?

Viewed 233

I am making a notification system for my Package Tracker app... I need to know how can I make this toast style more efficient than what I have now...

Things I'm looking to accomplish:

  1. when multiple notifications are shown have them docked from top to bottom on right of screen (looking for a better solution) <<< DONE!
  2. when 1 notification closes moves all notifications below it up... <<< DONE!

  3. Sticky Notifications Enabled when computer is idle. <<< DONE!

  4. if a Notification Exists for a particular item it is replaced rather than creating a new notification. <<< DONE!

To show a notification I use:

#region Check if Notification Exists

foreach (Form f in ActiveNotifications)
{
    string[] windowID = f.Text.Split('|');

    if (windowID[1] == NotificationTrackingNumber)
    {
        NotificationFound = true;
        f.Text = "Description=" + NotificationDescription;
        f.Text = "Status=" + NotificationStatus;
    }
}

#endregion Check if Notification Exists

if (NotificationFound)
{
    NotificationFound = false;
}
else if (!NotificationFound)
{
    notification = new Notification(NotificationDescription, NotificationStatus, NotificationTrackingNumber, min, sec, WindowID);
    notification.Closed += new EventHandler(Notification_Closed);
    notification.Show();
    ActiveNotifications.Add(notification);
    WindowID++;
}

To position them up and down the right side of the screen I use:

Rectangle res = Screen.PrimaryScreen.Bounds;           
this.Location = new Point(res.Width - 5 - Size.Width, (this.Height + 16) * multiplier + 6);

To re-position any Active Notifications that is below the closed notification

public void Notification_Closed(object sender, EventArgs e)
{
    WindowID--;
    List<Form> TempNotificationList1 = new List<Form>();
    List<Form> TempNotificationList2 = new List<Form>();
    Point newFormPoint = NotificationSettings.notificaionLocation;
    Point oldFormPoint;
    int delIndex = -1;
    int newWindowID = 0;
    int winHandleIndex = 0;
    int ClosedNotificationWindowID = NotificationSettings.WindowMultiplier;

    #region Deletes Closed Notification Window from ActivateNotifications

    while (winHandleIndex < ActiveNotifications.Count)
    {
        if (ActiveNotifications[winHandleIndex].Handle == NotificationSettings.notificationClosedID)
        {
            delIndex = winHandleIndex;
            break;
        }

        winHandleIndex++;
    }

    if (delIndex > -1)
    {
        ActiveNotifications.RemoveAt(delIndex);
    }

    #endregion Deletes Closed Notification Window from ActivateNotifications

    #region Changes the Location Active Notifications

    while (ClosedNotificationWindowID < ActiveNotifications.Count)
    {
        string[] windowID = ActiveNotifications[ClosedNotificationWindowID].Text.Split('|');
        oldFormPoint = ActiveNotifications[ClosedNotificationWindowID].Location;
        ActiveNotifications[ClosedNotificationWindowID].Location = newFormPoint;
        newFormPoint = oldFormPoint;
        TempNotificationList1.Add(ActiveNotifications[ClosedNotificationWindowID]);
        ClosedNotificationWindowID++;
    }

    #endregion Changes the Location Active Notifications

    #region Merges ActiveNotifications &  TempNotificationList1

    foreach (Form f in ActiveNotifications)
    {
        if (!TempNotificationList1.Contains(f))
        {
            TempNotificationList2.Add(f);
        }
    }

    foreach (Form f in TempNotificationList1)
    {
        if (!TempNotificationList2.Contains(f))
        {
            TempNotificationList2.Add(f);
        }
    }

    #endregion Merges ActiveNotifications &  TempNotificationList1

    #region Rebuilds Active Notifications List

    ActiveNotifications.Clear();
    foreach (Form f in TempNotificationList2)
    {
        string[] windowID = f.Text.Split('|');
        f.Text = newWindowID.ToString() + "|" + windowID[1];
        ActiveNotifications.Add(f);
        newWindowID++;
    }

    TempNotificationList1 = null;

    #endregion Rebuilds Active Notifications List
}

Well, the code works but is there a more efficient way? Multiplier is really just window count... here is a picture of how it's working as of now...

my notification Window as of now

0 Answers
Related