Click here to Skip to main content
11,572,401 members (50,424 online)
Click here to Skip to main content
Add your own
alternative version

Easy Desktop Web Stats

, 23 Oct 2012 CPOL 3.8K 99 4
Create a Windows desktop app to display daily web stats from your personal site
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Media;

using Compatibility;
using ContextMenuBuilder;

namespace Desktop_Web_Stats
{
    public partial class Main : Form
    {
        private delegate void AppInitializeDelegate();
        private AppInitializeDelegate performAppInitialize;
        
        private Properties.Settings settings = Properties.Settings.Default;

        private ContextMenu formContextMenu = new ContextMenu();  
        private Point nullRefPoint = new Point(-1, -1);
        private Timer savePositionTimer = new Timer();

        Form preferencesForm = new Desktop_Web_Stats.Preferences();

        public static bool preferencesChanged = false;

        public Main()
        {           
            InitializeComponent();            

            // declare Form context menu;
            string[] formMenuItemDescriptions = {"Preferences",
                                                 "Close the program"};

            EventHandler[] formMenuItemEventHandlers = {Preferences_Item_Click,
                                                        Close_Item_Click};

            this.ContextMenu = formContextMenu;            

            // append initialize methods to delegate;           
            performAppInitialize += RestoreLastPosition;
            performAppInitialize += Manage.StartupFolderLnk;
            performAppInitialize += (() => { Build.Menu(formMenuItemDescriptions, formMenuItemEventHandlers, formContextMenu); });    
            performAppInitialize += (() => { savePositionTimer.Tick += new EventHandler(savePositionTimer_Tick); });
            performAppInitialize += CreateDataRequestCycle;
        }        

        private void Main_Load(object sender, EventArgs e)
        {                    
            VouchSafe Verified = new VouchSafe();

            if (!Verified.compatibility())
            {
                CloseAndDispose();
            }            
            
            performAppInitialize();            
        }              

        private void RestoreLastPosition()
        {           
            if (settings.preferredLocation != nullRefPoint)
            {
                this.Location = settings.preferredLocation;
            }
        }
        
        private void savePositionTimer_Tick(object sender, EventArgs e)
        {
            savePositionTimer.Stop();
            settings.preferredLocation = this.Location;
            settings.Save();
        }

        private void CloseAndDispose()
        {           
            Dispose(true);
            Application.Exit();
        }

        private void Main_Move(object sender, EventArgs e)
        {
            // stop the timer if it is already running;
            savePositionTimer.Stop();
            // wait 8 seconds, then save the new position;
            savePositionTimer.Interval = 8000;
            savePositionTimer.Start();
        }             
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Michael J Hill - OH
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 23 Oct 2012
Article Copyright 2012 by Michael J Hill - OH
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid